Eqn = 
graph the function using ezplot() and plot()
Show older comments
clc
clear all
syms x
ezplot(@(x) -3*x^3+5*x ,[-2.5, 2.5])
plot()
I have a function 2y^2 = -3x^3+5x , -2.5≤x≤2.5.
I used ezplot, but it is not able to read the y function. How can I make a graph of the function using ezplot and plot?
1 Comment
Dr. Elangovan
on 22 Feb 2025
I don't know
Answers (2)
Geoff Hayes
on 17 Feb 2019
Jay - are you observing an error? If so, what is it?
Or do not use the syms x and just call
ezplot(@(x) -3*x^3+5*x ,[-2.5, 2.5])
You may see some warnings such as
Warning: Function failed to evaluate on array inputs; vectorizing the function may speed up
its evaluation and avoid the need to loop over array elements.
and so you can just do the following instead
ezplot(@(x) -3*x.^3+5*x ,[-2.5, 2.5])
where the anonymous function has been vectorized.
1 Comment
madhan ravi
on 17 Feb 2019
Agree with Geoff Hayes:
ezplot(@(x,y) -3*x.^3+5*x-2*y.^2) % adjust your limit for the two variables , see the doc for two variable limits
Perhaps this —
syms x y
% 2y^2 = -3x^3+5x , -2.5≤x≤2.5.
Eqn = 2*y^2 == -3*x^3+5*x % Add Operators
Eqn = isolate(Eqn, y)
y = rhs(Eqn)
xterm = solve(sqrt(-x)*sqrt(3*x^2-5))
infvals = double(xterm)
figure
fplot(y, [-2.5 2.5])
grid
xlabel('X')
ylabel('Y')
title("$"+string(latex(Eqn)+"$"), Interpreter='LaTeX', FontSize=16)
yfcn = matlabFunction(y)
xv = linspace(-2.5, 2.5, 250);
figure
plot(xv, abs(yfcn(xv)), DisplayName='|y(x)|')
hold on
plot(xv, real(yfcn(xv)), DisplayName='Re(y(x))')
plot(xv, imag(yfcn(xv)), DisplayName='Im(y(x))')
hold off
grid
xlabel('X')
ylabel('Y')
title("$"+string(latex(Eqn)+"$"), Interpreter='LaTeX', FontSize=16)
legend(Location='best')
xline(infvals, '--k', DisplayName='Discontinuity')
.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



