필터 지우기
필터 지우기

solve equation without fsolve

조회 수: 5 (최근 30일)
Max Bernstein
Max Bernstein 2011년 10월 18일
Hello,
I have the following equation that I'm trying to solve. I need to solve for T for a very long array of known RT
function RT=RTD(T)
a=0.003925;
b=0.110361;
d=1.492690;
R0=100;
RT=R0*(1+a*(1+d/100)*T-a*d/100^2*T^2+a*b/100^3*T^3-a*b/100^4*T^4);
I dont think I have fsolve or symbolic toolbox installed. Is there anyway to automate this without using those?
Thanks

답변 (3개)

Naz
Naz 2011년 10월 19일
Assuming that each RT will yield four roots:
a=0.003925;
b=0.110361;
d=1.492690;
R0=100;
T=zeros(4,length(RT));
for n=1:length(RT)
T(:,n)=roots(-a*b/100^4*R0 a*b/100^3*R0 -a*d/100^2*R0 a*(1+d/100)*R0 (1-RT(n))*R0);
end
If you want to create an actual function, go to file->new->script and paste the following:
function [T]=RTD(RT)
a=0.003925;
b=0.110361;
d=1.492690;
R0=100;
T=zeros(4,length(RT));
for n=1:length(RT)
T(:,n)=roots(-a*b/100^4*R0 a*b/100^3*R0 -a*d/100^2*R0 a*(1+d/100)*R0 (1-RT(n))*R0);
end
end
Then you can call this function and pass your array of RT. The function will return you an array of T.
T=RTD(RT)
P.S. Make sure there is enough parenthesis in the equation so the coefficients are calculated properly. I recommend to calculate the coefficients prior sending them to roots function. This also will save some time, since the coefficients will be calculated only once instead of each loop.
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 10월 19일
You left out the [] in that roots() call, so this code will end up taking roots() of a scalar.

댓글을 달려면 로그인하십시오.


Andrei Bobrov
Andrei Bobrov 2011년 10월 19일
a=0.003925;
b=0.110361;
d=1.492690;
R0=100;
syms k T
cf = coeffs(k-R0*(1+a*(1+d/100)*T-a*d/100^2*T^2+a*b/100^3*T^3-a*b/100^4*T^4),T)
fcf = matlabFunction(cf(end:-1:1))
RTD = @(RT)cell2mat(arrayfun(@(x)roots(fcf(x)),RT,'un',0))
use function RTD
T = RTD(RT)
  댓글 수: 1
Valerio
Valerio 2013년 7월 18일
I have used your proposed solution, but the output variable of Temp = RTD(RT) is the sym T. What is the problem? Can you help me?
Thanks

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 10월 18일
roots( [R0*a*b, -100*R0*a*b, 10000*R0*a*d, -100000000*R0*a-1000000*R0*a*d, -100000000*R0+100000000*RT] )
Note that roots() can only process one set of coefficients at a time: it is not vectorized.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by