Cant find roots with fzero

This is pretty straight forward.
I have to following equation:
syms T
Qbalance(T) =(2585111364437669*T)/2251799813685248 + (7434051551537793*(T + 273)^4)/4835703278458516698824704 - 4489244199846279/70368744177664
And I'm trying to find one of the possible roots by using fzero: fzero(Qbalance,40) I know that one root is ~42 :-)
But it doesnt seem to work. Any idea what I can do to make it work anywhere between T = [-100 100] ?
Thanks!

1 comentario

Torsten
Torsten el 8 de Jun. de 2015
fzero does not work with symbolic variables or expressions.
Use "solve" instead.
Best wishes
Torsten.

Iniciar sesión para comentar.

Respuestas (2)

Titus Edelhofer
Titus Edelhofer el 8 de Jun. de 2015

0 votos

Hi,
either do what Torsten suggests, or create a function handle instead of using syms:
Qbalance = @(T) (2585111364437669*T)/2 ...
And yes, it's 42:
answerToEverything = round(fzero(Qbalance, 40))
answerToEverything =
42
;-)
Titus

2 comentarios

Jarl Bergström
Jarl Bergström el 8 de Jun. de 2015
Thank you very much for your replay!
The thing is, that doesn't seems to work if I have:
syms T
a=1+T
b=T
and then Q = @(T) a+b or Q=a+b
How can I put that equation into fzero?
The reason for why I dont want to use solve is because I get 4 roots and I don't know how to separate the correct one, because T can be both positive and negative.
Q = matlabFunction(a+b);

Iniciar sesión para comentar.

John D'Errico
John D'Errico el 8 de Jun. de 2015
Editada: John D'Errico el 8 de Jun. de 2015

0 votos

No. It is NOT 42. Close, but no cigar. Unless of course, you round the result as did Titus. :)
If you are going to use syms, then why in the name of god and little green apples, why not solve? This is a 4th order polynomial after all.
syms T
Qbalance = (2585111364437669*T)/2251799813685248 + (7434051551537793*(T + 273)^4)/4835703278458516698824704 - 4489244199846279/70368744177664;
vpa(solve(Qbalance))
ans =
-1270.5696869775977378281084791948
42.330660289301496605774980024324
68.119513344148120611166749585241 + 814.64831383344987959986838110296i
68.119513344148120611166749585241 - 814.64831383344987959986838110296i
Looks like more like 42.33066... to me.
roots(sym2poly(Qbalance))
ans =
-1270.5696869776 + 0i
68.1195133441485 + 814.64831383345i
68.1195133441485 - 814.64831383345i
42.3306602893015 + 0i
Roots agrees.
Qbalance = @(T) (2585111364437669*T)/2251799813685248 + (7434051551537793*(T + 273).^4)/4835703278458516698824704 - 4489244199846279/70368744177664;
ezplot(Qbalance,[41,43])
grid on
Yep, the plot says so too. As does fzero, with absolutely no problems.
format long g
fzero(Qbalance,[0,100])
ans =
42.3306602893015

4 comentarios

Jarl Bergström
Jarl Bergström el 8 de Jun. de 2015
Thank you very much for your replay!
The things is. I don't know how to separate the correct answer (in this case 42 :-) ) from -1270 which is also a "correct" solution. T can be both positive and negative.
Titus Edelhofer
Titus Edelhofer el 8 de Jun. de 2015
Hi Jarl,
I'm not sure where the problem is: John's code shows using the symbolic toolbox both real results (-1270.56... and 42.33...). The call to fzero that I wrote gives the same 42.33... without problem (forget the fun about rounding). So what piece is missing? You need to tell us, why 42 is a better solution than -1270. I could imagine that "T" denotes temperature, so it should be larger than -273 I guess, is it this? So why not take the 42.33...?
Titus
Tewodros Bitaw
Tewodros Bitaw el 15 de Mzo. de 2017
Editada: Tewodros Bitaw el 15 de Mzo. de 2017
Hi Jarl I think this works better.
syms T
T0=298.15;
Qbalance(T) =(2585111364437669*T)/2251799813685248 + (7434051551537793*(T + 273)^4)/4835703278458516698824704 - 4489244199846279/70368744177664 Q=matlabFunction(Qbalance(T))
T=fzero(Q,T0)
T =
42.3307
Walter Roberson
Walter Roberson el 15 de Mzo. de 2017
4835703278458516698824704 cannot be kept at full precision in the form shown.
syms T positive
Q = @(v) sym(v,'r');
T0 = Q(298.15);
Qbalance(T) =(sym('2585111364437669')*T)/sym('2251799813685248') + (sym('7434051551537793')*(T + sym(273))^4)/sym('4835703278458516698824704') - sym('4489244199846279')/sym('70368744177664')
solve(Qbalance(T))
The solution (in recent MATLAB) is
root(z^4 + 1092*z^3 + 447174*z^2 + (6156509634857202603287236*z)/7434051551537793 - 89068512980281706423859477/2478017183845931, z, 2)
which can be found to arbitrary precision using vpa(), or converted to double precision with double()

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 8 de Jun. de 2015

Comentada:

el 15 de Mzo. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by