MATLAb Solve function not solving
7 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Steven Lord
2024-10-21,18:54
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 个评论
更多回答(3 个)
Torsten
2024-10-21,18:38
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 个评论
Star Strider
2024-10-21,18:42
编辑:Star Strider
2024-10-21,18:47
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 个评论
Taylor
2024-10-21,18:45
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!