How to use a fzero function and subfunctions?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stasha
el 3 de Dic. de 2013
Comentada: Stasha
el 3 de Dic. de 2013
Hi,
I am working on a code that involves using an fzero function but I can't figure out how to make it work. I need to find the density of air. This is what I have thus far.
%Parameters
T=250; Tb=340; Bstr=20.5*10^6; b_4=-0.00168785; b_3=-0.0223299;
b_2=-0.1704; b_1=-1.94783; b0=2.16059; b1=-0.0222243; c_3=2.50287;
c_2=-5.52109; c_1=4.29631; c0=1.19665; R=8.314; P=0.01;
tau=T/Tb;
B=Bstr*(b_4*tau^-4+b_3*tau^-3+b_2*tau^-2+b_1*tau^-1+b0*tau^0+b1*tau^1);
C=Bstr^2*(c_3*tau^-3+c_2*tau^-2+c_1*tau^-1+c0*tau^0);
x0=(initalguess);
x=fzero(@func1,x0);
p=0.029*pbar;
5 comentarios
Más respuestas (1)
sixwwwwww
el 3 de Dic. de 2013
Your code is working but its not giving correct ans because of your initial condition:
%Parameters
T=250;
Tb=340;
Bstr=20.5*10^6;
b_4=-0.00168785;
b_3=-0.0223299;
b_2=-0.1704;
b_1=-1.94783;
b0=2.16059;
b1=-0.0222243;
c_3=2.50287;
c_2=-5.52109;
c_1=4.29631;
c0=1.19665;
%Equation 2
tau=T/Tb;
B=Bstr*(b_4*tau^-4+b_3*tau^-3+b_2*tau^-2+b_1*tau^-1+b0*tau^0+b1*tau^1);
C=Bstr^2*(c_3*tau^-3+c_2*tau^-2+c_1*tau^-1+c0*tau^0);
x0 = 1;
x = fzero(@(pbar)1+B*pbar+C*pbar^2 ,x0) ;
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!