
question related to direction field
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
equation: x*y'+y-(1+x)*exp(x)=0
domain [-2, 1] [-2, 2]
initial values y(-1)=-1 y(-1)=1 y(1/2)=1
code:
syms y(x);
eqn = x*diff(y,x)+y-(1+x)*exp(x)==0;
dsolve(eqn)
x = -2:0.3:1;
y = -2:0.3:2;
[X,Y] = meshgrid(x,y);
DY =;
DX = ones(size(DY))
quiver(X,Y,DX,DY)
hold on
x=-2:0.01:1;
y1 =;
plot(x,y1,'g')
y2= ;
plot(x,y2,'r')
y3= ;
plot(x,y3,'y')
xlim ([-2 2])
ylim([-2 2])
the task is :to plot the direction field over the given domain and plotting on the same figure the curves belonging to the given initial values.
im just stuck with what should i write instead of DY and how can i plot the initial values on the same curve (what should i write instaed of y1,y2,y3 ) if any one can help
0 Kommentare
Akzeptierte Antwort
Sam Chak
am 16 Mär. 2022
Hi @SSBGH
The solutions for the initial conditions,
,
, and
are given by
The direction field for
can be plotted with
[X, Y] = meshgrid(-3:6/15:3, -16:36/15:20);
S = ((1 + X).*exp(X) - Y)./X;
L = sqrt(1 + S.^2);
U = 1./L;
V = S./L;
quiver(X, Y, U, V, 0.25)
To add the trajectories of
,
, and
on the direction field, the current plot must be retained.
hold on
x = linspace(-3, 3, 301);
y1 = exp(x) + 1./x + 1./(exp(1)*x);
y2 = exp(x) - 1./x + 1./(exp(1)*x);
y3 = (1 - sqrt(exp(1)) + 2*exp(x).*x)./(2*x);
plot(x, y1, x, y2, x, y3)
hold off
axis([-3 3 -16 20])
Result:

Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!