Eqn = 
graph the function using ezplot() and plot()
Afficher commentaires plus anciens
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 commentaire
Dr. Elangovan
le 22 Fév 2025
I don't know
Réponses (2)
Geoff Hayes
le 17 Fév 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 commentaire
madhan ravi
le 17 Fév 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')
.
Catégories
En savoir plus sur Calculus dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




