Linear equation with multiple values for a constant
1 view (last 30 days)
Show older comments
Ahsan Muhammad
on 27 Aug 2015
Commented: Star Strider
on 28 Aug 2015
Hi Everyone,
I am trying to solve these 2 equation simultaneously, Dx+4y=2, Dx+2y=4 for 2 values of D which are 1 and 3. I have written the code but it only gives 1 value. Help will be great. Thanks
>> D=[1 2];
for k=1:length(D)
Z=solve([D(k)*x+4*y==2,D(k)*x+2*y==4],[x,y])
end
Z =
x: [1x1 sym]
y: [1x1 sym]
Z =
x: [1x1 sym]
y: [1x1 sym]
>> Z.x
ans =
3
0 Comments
Accepted Answer
Star Strider
on 27 Aug 2015
It will give both of them for both values of ‘D’ if you ask it to:
syms x y
D=[1 2];
for k=1:length(D)
Z{k} = solve([D(k)*x+4*y==2,D(k)*x+2*y==4],[x,y]);
end
D1 = [Z{1}.x; Z{1}.y]
D2 = [Z{2}.x; Z{2}.y]
D1 =
6
-1
D2 =
3
-1
2 Comments
Star Strider
on 27 Aug 2015
Ahsan Muhammad’s Answer moved here:
OMG you are a legend Star Strider, thank you so much Heres another query
S=solve([C1*(A*x+B1*y^(1/N1))^-1 + C2*(A*x+B2*y^(1/N2))^-1 == 1, x/(y*N1)*(C1*(A*x+B1*y^(1/N1))^-1) + x/(y*N2)*(C2*(A*x+B2*y^(1/N2))^-1)==1],[x,y])
This code runs fine, i have defined values for everything except x and y. But it takes 4 - 5 hours. Is there a faster way to do this?
Star Strider
on 28 Aug 2015
More Answers (0)
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!