Solve matrix in the equation

1 view (last 30 days)
Redwood
Redwood on 30 Apr 2013
Dear Matlab experts,
I would like to get b values, but I think my coding is wrong. Please let me know how to get the b values.
syms b G = [7340, 7194]; G1 = [4516.881,5002.953]; M1 =[ 5222.328, 6009.419]; M2 =[3264.034, 2632.621]; P1 =[3000, 3025]; P2 =[10000, 10051]; Out=solve(G1 == G*(P1*exp(-b*M1/P1)/( P1*exp(-b*M1/P1)+ P2*exp(-b*M2/P2))), b) Out=double(out)
Thank you very much in advance.
Sincerely yours,
Redwood

Answers (2)

Roger Stafford
Roger Stafford on 30 Apr 2013
You can't use the 'solve' function with vector inputs in that manner. You should leave all six parameters as symbols and let 'solve' obtain a general solution for 'b' as a function of them. Then use matlab to evaluate this function for your vector inputs.
Actually you don't even need 'solve' in this very elementary case. You can solve it yourself with simple algebra. The following equations are equivalent:
G1 = G*(P1*exp(-b*M1/P1)/(P1*exp(-b*M1/P1)+ P2*exp(-b*M2/P2)))
G1/G = 1/(1+P2/P1*exp(-b*(M2/P2-M1/P1)))
P2/P1*exp(-b*(M2/P2-M1/P1)) = G/G1 - 1
exp(-b*(M2/P2-M1/P1)) = (G/G1-1)*P1/P2
-b*(M2/P2-M1/P1) = log((G/G1-1)*P1/P2)
b = -log((G/G1-1)*P1/P2)/(M2/P2-M1/P1)
This last equation is your general solution for b in terms of the six parameters, so evaluate it directly with matlab:
b = -log((G./G1-1).*P1./P2)./(M2./P2-M1./P1);

Zhang lu
Zhang lu on 1 May 2013
Edited: Zhang lu on 1 May 2013
syms b G G1 M1 M2 P1 P2
Out=solve('G*(P1*exp(-b*M1/P1)/( P1*exp(-b*M1/P1)+ P2*exp(-b*M2/P2)))-G1', b)
G = [7340, 7194];
G1 = [4516.881,5002.953];
M1 =[ 5222.328, 6009.419];
M2 =[3264.034, 2632.621];
P1 =[3000, 3025];
P2 =[10000, 10051];
Out=subs(Out)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!