Differential System Of Equations
Mostra commenti meno recenti
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')
Risposta accettata
Più risposte (1)
madhan ravi
il 19 Gen 2019
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

Categorie
Scopri di più su Debugging and Improving Code in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
