question related to direction field

조회 수: 2 (최근 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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by