![Differential System Of Equations - 2019 01 18.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/144925/Differential%20System%20Of%20Equations%20-%202019%2001%2018.png)
Differential System Of Equations
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to find answers to specific input (t=20)
But my code keeps out putting strange equations without all the variable
I'd appreciate it if anyone can show me why this output is like that
For example the first line below is part of the output I dont understand what the #X is
xSol(t) =
(exp(root(#X^3 + (5*#X)/4 - 2^(1/2)/8, #X, 3)*t)*(2^(1/2)
clc, clear
syms x(t) y(t) z(t)
ode1 = diff(x,t) == z - (1/2)*y;
ode2 = diff(y,t) == (1/2)*x - (1/(sqrt(2)))*z;
ode3 = diff(z,t) == (1/(sqrt(2)))*y - (1/2)*x;
odes = [ode1; ode2; ode3];
cnd1 = x(0) == 1;
cnd2 = y(0) == 0;
cnd3 = z(0) == 0;
conds = [cnd1; cnd2; cnd3];
[xSol(t), ySol(t), zSol(t)] = dsolve(odes, conds)
fplot(xSol)
hold on
fplot(ySol)
hold on
fplot(zSol)
grid on
legend('xSol','ySol', 'zSol')
댓글 수: 0
채택된 답변
Star Strider
2019년 1월 18일
편집: Star Strider
2019년 1월 19일
No mystery at all.
Add these three assignments after your dsolve call:
xSolvpa = vpa(xSol)
ySolvpa = vpa(ySol)
zSolvpa = vpa(zSol)
and the functions resolve to:
xSolvpa(t) =
0.39703503403676880167413394762852*exp(0.13926074738154957998312484530008*t) + exp(t*(- 0.069630373690774789991562422650042 - 1.1245199717305828384502799984853i))*(0.30148248298161559916293302618574 - 0.0059166222071075799552646099750859i) + exp(t*(- 0.069630373690774789991562422650042 + 1.1245199717305828384502799984853i))*(0.30148248298161559916293302618574 + 0.0059166222071075799552646099750859i)
ySolvpa(t) =
0.32349030593970774096648972843982*exp(0.13926074738154957998312484530008*t) - exp(t*(- 0.069630373690774789991562422650042 - 1.1245199717305828384502799984853i))*(0.16174515296985387048324486421991 - 0.19227126160807200590439356187362i) - exp(t*(- 0.069630373690774789991562422650042 + 1.1245199717305828384502799984853i))*(0.16174515296985387048324486421991 + 0.19227126160807200590439356187362i)
zSolvpa(t) =
0.21703654854647326974599442155993*exp(0.13926074738154957998312484530008*t) - exp(t*(- 0.069630373690774789991562422650042 - 1.1245199717305828384502799984853i))*(0.10851827427323663487299721077996 + 0.24247546582044825480541269698659i) - exp(t*(- 0.069630373690774789991562422650042 + 1.1245199717305828384502799984853i))*(0.10851827427323663487299721077996 - 0.24247546582044825480541269698659i)
If you want to use them numerically, use the matlabFunction (link) function. That will convert them to anonymous functions.
EDIT —
To evaluate them and plot them:
x20 = xSolvpa(20) % Evaluate At t=20
y20 = ySolvpa(20) % Evaluate At t=20
z20 = zSolvpa(20) % Evaluate At t=20
fplot(xSolvpa, [0 30])
hold on
fplot(ySolvpa, [0 30])
hold on
fplot(zSolvpa, [0 30])
grid on
legend('xSol','ySol', 'zSol', 'Location','N')
They evaluate to complex results, although you can safely ignoire the imaginary parts, since they are vanishingly small:
x20 =
6.3031762131597174425074106544313 + 1.1479437019748901445007192746311e-41i
y20 =
5.2664281481456048004144813508306 - 2.2958874039497802890014385492622e-41i
z20 =
3.6217244010970352709039208520563
![Differential System Of Equations - 2019 01 18.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/144925/Differential%20System%20Of%20Equations%20-%202019%2001%2018.png)
댓글 수: 0
추가 답변 (1개)
madhan ravi
2019년 1월 19일
ic = [1;0;0]; % initial conditions
tspan = [0 20];
[t,x]=ode45(@myod,tspan,ic); % function call
when_t_is_20 = x(t==20,:) % solution 1 , 2 & 3
figure
plot(t,x,'-o')
h=legend('x(t)','y(t)','z(t)');
h.FontSize=20;
function dxdydz = myod(t,x) % function definition (save it in a separate file named myod.m)
% x=x(1);
% y=x(2);
% z=x(3);
dxdydz = zeros(3,1);
dxdydz(1) = x(3) - (1/2)*x(2);
dxdydz(2) = (1/2)*x(1) - (1/(sqrt(2)))*x(3);
dxdydz(3) = (1/(sqrt(2)))*x(2) - (1/2)*x(1) ;
end
![Screen Shot 2019-01-19 at 10.13.50 AM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/144887/Screen%20Shot%202019-01-19%20at%2010.13.50%20AM.png)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!