Ploting solutions to linear equations
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mike Chan
il 16 Nov 2019
Commentato: Star Strider
il 19 Nov 2019
Consider the linear system of equations x' = Ax. Let x(t)=[x1(t), x2(t), x3(t)]T be the unique solution such that x(0) = v1. In the same figure, I want to plot plot each of the functions x1(t), x2(t) and x3(t). I dont think I should have to use ODE 45. I have already looked on the matlab website to no avail.
M = [7 7 7; 2 6 7; 4 3 1];
B = transpose(M);
A = M+B;
[V,D]=eig(A);
lambda1= -5.9049;
v1= [-0.3429 -0.3208 0.8829];
% part c
syms x(t) y(t) % I use x(t) and y(t) to represent x1' and x2'
Y = [x; y];
odes = diff(Y) == A*Y %matlab keeps saying there is a problem with this line and I dont know why
[xSol(t), ySol(t)] = dsolve(odes);
xSol(t) = simplify(xSol(t));
ySol(t) = simplify(ySol(t));
C = Y(0) == [-0.3429 -0.3208 0.8829];
[xSol(t), ySol(t)] = dsolve(odes,C)
clf
fplot(ySol)
hold on
fplot(xSol)
grid on
savefig('symmetric.fig')
0 Commenti
Risposta accettata
Star Strider
il 16 Nov 2019
The ‘A*Y’ operation attempts to multiply (3x3) matrix ‘A’ by a (2x1) vector ‘Y’. That will just never work!
The ‘Y’ vector must be (3x1) to do that multiplication.
2 Commenti
Star Strider
il 19 Nov 2019
The Symbolic Math Toolbox appears not to be able to solve that, even though it is a linear system, and actually has an analytic solution.
Try this instead:
M = [7 7 7; 2 6 7; 4 3 1];
B = transpose(M);
A = M+B;
[V,D]=eig(A);
lambda1= -5.9049;
v1= [-0.3429 -0.3208 0.8829];
% part c
syms x(t) y(t) z(t) t Y
Y = [x; y; z];
odes = diff(Y) == A*Y
[VF,Sbs] = odeToVectorField(odes)
odesfcn = matlabFunction(VF, 'Vars',{'t','Y'})
t = linspace(0, 0.3, 50);
Y0 = [-0.3429 -0.3208 0.8829];
[T,xyz] = ode45(odesfcn, t, Y0);
figure
plot(t,xyz)
grid
legend(string(Sbs))
Parenthetically, I have no idea what the problem is with odeFunction. It used to take a cell array of symbolic variables:
odesfcn = matlabFunction(VF, 'Vars',{t,Y})
without problems, and that is still in the documentation for it. Now, it requires them to be a cell array of character vectors, and will not work without defining them with single quotes, as I did here.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Equation Solving in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!