How to use the solve function with a changing parameter?

Hi all,
I am working on an allocation problem that changes over time. I am hoping to find quantities a,b,c,d given this system of 4 equations. My problem is, I need to add a for loop where t changes symbolic of years. How can I input changing parameters to this solve function? When I run as it is it says "explicit solution cannot be found". I know this is not true because when I manually enter the numbers it works. I need t to ultimately be t=1:100 so that is why I do not want to do this without a loop.
for T=1:5
t=double(T);
% 532K
syms a b c d t;
[a, b, c, d]=solve('(a/(1.01^t)*1.499424825623625e+06)^(-1/.3)-977.55=(b/(1.01^t)*1.658846640009515e+07)^(- 1/0.75)-977.55','(a/(1.01^t)*1.499424825623625e+06)^(-1/.3)-977.55=(c/2.415456478597783e+07)^(- 1/1.5)-30','(a/(1.01^t)*1.499424825623625e+06)^(-1/.3)-977.55=(d/5.477225575051662e+05)^(-1/0.5)- 30','a+b+c+d = 532000');
MI_in1=double(a);
MI_out1=double(b);
Irr_crop1=double(c);
Irr_veg1=double(d);
Quant1=[MI_in1,MI_out1,Irr_crop1,Irr_veg1];
end

답변 (1개)

Roger Stafford
Roger Stafford 2014년 11월 10일

2 개 추천

There is an important difference between solving your equations symbolically in terms of t, as compared with solving them with t as a given single numerical value. Apparently 'solve' is able to do the latter but not the former. (I would be very surprised if it could do the former with your equations.)
Change your for-loop so that 't' is not a symbolic quantity but assumes each of the numerical values t = 1:100, one at a time. For each value of 't' store the corresponding values of a, b, c, and d in appropriate arrays as you solve them.
An alternate method would be to solve algebraically for 'b', 'c', and 'd' in terms of 'a', in the first three equations and after substituting the solutions into the fourth equation, you have a single equation in a single unknown, 'a'. Then call on 'fzero' for each value of 't' to find a corresponding 'a'. Having found it, then you can easily determine 'b', 'c', and 'd'.

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

질문:

2014년 11월 9일

답변:

2014년 11월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by