question related to direction field

3 ビュー (過去 30 日間)
SSBGH
SSBGH 2022 年 3 月 16 日
コメント済み: SSBGH 2022 年 4 月 15 日
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

採用された回答

Sam Chak
Sam Chak 2022 年 3 月 16 日
The solutions for the initial conditions, , , and are given by
,
,
, respectively.
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:
  1 件のコメント
SSBGH
SSBGH 2022 年 4 月 15 日
thanks alot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by