graph the function using ezplot() and plot()

4 次查看(过去 30 天)
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?

回答(2 个)

Geoff Hayes
Geoff Hayes 2019-2-17
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 个评论
madhan ravi
madhan ravi 2019-2-17
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

请先登录,再进行评论。


Star Strider
Star Strider 2025-2-22
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.
.

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by