Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use ezplot in MATLAB?

Tags:

plot

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)?


1 Answers

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

like image 198
gnovice Avatar answered Dec 31 '25 13:12

gnovice



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!