MATLAb Solve function not solving
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Antonio Olinto
el 21 de Oct. de 2024
Respondida: Steven Lord
el 21 de Oct. de 2024
I am trying to solve a system of equations in Matlab, however when I run the code below, it doesn't return an answer for I1, I2 and V0, although there 3 equations and 3 variables. I need some help.
clear all
close all
syms I1 I2 V0
s=2;
eqns=[5*I1+4*I2+1/(s*0.1)*I1+2*s*I1==1, 4*I2-3*V0==0, V0==I1*(2*s)];
S=solve(eqns,[I1,I2,V0])
0 comentarios
Respuesta aceptada
Steven Lord
el 21 de Oct. de 2024
I ran the code using release R2019a and it seems to have worked correctly, giving results that match what others have posted in previous answers.
>> syms I1 I2 V0
s=2;
eqns=[5*I1+4*I2+1/(s*0.1)*I1+2*s*I1==1, 4*I2-3*V0==0, V0==I1*(2*s)];
S=solve(eqns,[I1,I2,V0])
S =
struct with fields:
I1: [1×1 sym]
I2: [1×1 sym]
V0: [1×1 sym]
>> S.I1
ans =
1/26
>> S.I2
ans =
3/26
>> S.V0
ans =
2/13
>> version
ans =
'9.6.0.1072779 (R2019a)'
The display of the struct S doesn't show the values of the symbolic expressions but the fields do contain those values as you can see by displaying each of the individual fields on their own.
Can we check that those values are the correct solutions? Sure, substitute the results back into the equations using subs.
>> subs(eqns, S)
ans =
[ 1 == 1, 0 == 0, 2/13 == 2/13]
Those look like true expressions to me.
0 comentarios
Más respuestas (3)
Torsten
el 21 de Oct. de 2024
Which MATLAB version are you using ? R2024b gives a direct answer:
clear all
close all
syms I1 I2 V0
s=2;
eqns=[5*I1+4*I2+1/(s*0.1)*I1+2*s*I1==1, 4*I2-3*V0==0, V0==I1*(2*s)];
S=solve(eqns,[I1,I2,V0])
0 comentarios
Star Strider
el 21 de Oct. de 2024
Editada: Star Strider
el 21 de Oct. de 2024
Your code works in R2024b —
clear all
close all
syms I1 I2 V0
s=2;
eqns=[5*I1+4*I2+1/(s*0.1)*I1+2*s*I1==1, 4*I2-3*V0==0, V0==I1*(2*s)];
S=solve(eqns,[I1,I2,V0])
format long
I1 = double(S.I1)
I2 = double(S.I2)
V0 = double(S.V0)
Consider upgrading, if that is an option. (I no longer have access to R2019a to see if there could be a work-around.)
EDIT — Changed vpa calls to double, since symbolic results no longer appear here after a post is submittted.
.
0 comentarios
Taylor
el 21 de Oct. de 2024
Seems to work fine here
clear all
close all
syms I1 I2 V0
s=2;
eqns=[5*I1+4*I2+1/(s*0.1)*I1+2*s*I1==1, 4*I2-3*V0==0, V0==I1*(2*s)];
S=solve(eqns,[I1,I2,V0])
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!