Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

plot - How to use ezplot in MATLAB?

I want to use ezplot in MATLAB, and because the function I want to plot consists of a large number of terms I may split it into smaller functions. Let me give an example of a small number of terms and it can be generalized to a large number of terms. To plot the function:

y2+xy+xy3+x+1=0

I let y1=x+1 and I write the following in MATLAB:

x=[0:1:5]
y1=x+1
ezplot('y.^2+x*y+x*y.^3+y1')

But there is an error. Please tell me how can I correct the error. Is it possible to use this feature (splitting the equation or function into a number of terms)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your error is caused by trying to replace x+1 with y1. ezplot requires that symbolic expressions are functions of only 2 symbolic variables. However, there are 3 symbolic variables (x, y, and y1) in your call to ezplot:

ezplot('y^2+x*y+x*y^3+y1');

If you use your original equation, everything should work fine:

ezplot('y^2+x*y+x*y^3+x+1');

enter image description here


EDIT: In case you were curious...

If you want to plot an equation with 3 variables, you will first need to solve the equation for one of them and then use the function ezsurf (this is illustrated in this answer I gave to another SO question). Technically, y1 is a dependent variable the way you have defined it (since it depends on the variable x). However, for the sake of the following example, let's assume it's an independent variable. The equation:

y^2 + x*y + x*y^3 + y1 = 0

would be solved for y1 to get the following:

y1 = -y^2 - x*y - x*y^3

and y1 would be plotted in the following way:

ezsurf('-y^2-x*y-x*y^3');

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...