how to find value T for every x so that the result of a functions e(T,x) is (for example) 0.1

i have a following question:
in this equation: ex=(1.006+x*1.926)*To*(T/To-1-ln(T/To))+0.287042*To*((1+1.608*x)*ln((1+1.608*x)/(1+1.608*xo))+1.608*x*ln(x/xo))
To and xo are known and have fixed values. i have to find T for every x from 0 to 20, which gives value ex=0.1. for some x's T might not exist, for others there are two values for T which give correct value ex=0.1.
i hope i explained this ok... thanks, BR

 Accepted Answer

doc fsolve
By your description it's a single variable to solve for a zero at a series of x values.
Wrapping fsolve in a loop over x in a try...catch block for the cases that fail should work it would seem...

3 Comments

Or fzero, if you don't have the Optimization Toolbox.
Actually, fzero was really what I was intending, not sure where fsolve came from...
this is what I did: because for every x there are two solutions T, i used fzero two times... for lowest and highest x, temperatures should be the same, but they are not... in this case the lowest x is 0.00535 and temperatures are g=28.98 C and z=23.04... the highest x is 11.8 and temperatures are g=29.01 C and z=23.00. if I change the initial values from 5 (z) and 80 (g) to some other values then even the highest and lowest x calculated with each function are not the same, but slightly different... any ideas what is wrong? you can replicate this problem with my code copied below. thanks!
xo=0.008369
To=26
ex=0.1
x=[0.00000000000000001:0.00005:0.025]
Tempg=[]
Tempz=[]
for i=1:501
xi=x(i)
f=@(T)(1.006+xi*1.926)*293.15*((T+273.15)/(To+273.15)-1-log((T+273.15)/(To+273.15)))+0.287042*(To+273.15)*((1+1.608*xi)*log((1+1.608*xo)/(1+1.608*xi))+1.608*xi*log(xi/xo))-ex
z=fzero(f,5)
g=fzero(f,80)
Tig=g
Tiz=z
Tempg=[Tempg Tig]
Tempz=[Tempz Tiz]
end

Sign in to comment.

More Answers (0)

Categories

Tags

Asked:

on 21 Sep 2013

Community Treasure Hunt

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

Start Hunting!