graph the function using ezplot() and plot()

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?

Réponses (2)

Geoff Hayes
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

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

Connectez-vous pour commenter.

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 = 
Eqn = isolate(Eqn, y)
Eqn = 
y = rhs(Eqn)
y = 
xterm = solve(sqrt(-x)*sqrt(3*x^2-5))
xterm = 
infvals = double(xterm)
infvals = 3×1
0 -1.2910 1.2910
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
fplot(y, [-2.5 2.5])
grid
xlabel('X')
ylabel('Y')
title("$"+string(latex(Eqn)+"$"), Interpreter='LaTeX', FontSize=16)
yfcn = matlabFunction(y)
yfcn = function_handle with value:
@(x)(sqrt(2.0).*sqrt(-x).*sqrt(x.^2.*3.0-5.0))./2.0
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')
The isolate function was introduced in R2017a.
.

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by