Is It possible create a function that, given an equation, finds the value of the (x) so the two members are equal?

조회 수: 1 (최근 30일)
Hi,
I have the previous problem and consists in finding the values of (Mach) and (pp1). I thought to find then the values of (Mach) and (pp1) such that the two members of the equation are equal and I used the function "fsolve" but without acceptable results (I have insert my personal script and linked function). Is it possible use the construct "while"?
  댓글 수: 3
Gianmarco Moccia
Gianmarco Moccia 2019년 5월 6일
편집: Gianmarco Moccia 2019년 5월 6일
These are the equations and I need to valuate the quantities (Mp1) and (pp1) and I propose the following script file and linked function file but the result is not acceptable
%DATI_INPUT_GEOMETRICI
Dt=2.82 %mm
At=6.2458 %mm^2
Dp1=5.10 %mm
Ap1=20.4282 %mm^2
A3=66.4761 %mm^2
%DATI_INPUT_TERMODINAMICI
pev=0.040 %Mpa
Tev = 8 %°C
pg=0.604 %Mpa
Tg=95 %°C
cp= 0.85 %[kJ/(kg*K)]
gam=1.2 R=0.143 %[kJ/(kg*K)]
eta_p=0.95
Msy=1
lossp=0.88
etap = 0.95
%Algoritmo
%Calcolo porata massica del primario
mp=((pg*At)/sqrt(Tg))*sqrt((gam/R)*(2/(gam+1))^((gam+1)/(gam-1)))*sqrt(eta_p)
%Calcolo della pressione del fluido primario e del numero di Mach del %primario nella sezione 1
x0=[1.1,0.1]; xsol = fsolve(@(x)NLfunctions1(x), x0)
return
Function file
function F = NLfunctions1(x)
Ap1=20.4282
At=6.2458
gam=1.2
pg=0.604
%definizione funzioni
F = (Ap1/At)^2 - ((1/(x(1))^2))*[(2/(gam+1))*(1+((gam-1)/(2)))(x(1))^(2))]^((gam+1)/(gam-1));
F = ((pg)/(x(2)))-(1+(((gam-1)/(2))*x(1)^(2))^(gam/(gam-1)));
end
dpb
dpb 2019년 5월 7일
Sorry, I ran out of time last night...didn't have chance to do anything -- but, one thing I notice that is problem in the NLFunctions1 routine -- you don't return a 2-vector of the the two equations--but only one.
See if
function F = NLfunctions1(x)
Ap1=20.4282
At=6.2458
gam=1.2
pg=0.604
%definizione funzioni
F(1) = (Ap1/At)^2 - ((1/(x(1))^2))*[(2/(gam+1))*(1+((gam-1)/(2)))(x(1))^(2))]^((gam+1)/(gam-1));
F(2) = ((pg)/(x(2)))-(1+(((gam-1)/(2))*x(1)^(2))^(gam/(gam-1)));
end
won't help...

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

답변 (1개)

David Goodmanson
David Goodmanson 2019년 5월 7일
Hi Gianmarco,
the two equations aren't coupled, and using fzero on Mp^2 seems to work. In the first equation I multiplied by both sides by Mp^2 and took both sides to the (gam-1)/(gam+1) power, so the variations in the functions are smaller and the search limits are easier to guess.
At=6.2458; % mm^2
Ap1=20.4282; % mm^2
pg=0.604; % Mpa
gam=1.2;
fun1 = @(m2) (m2*(Ap1/At)^2).^((gam-1)/(gam+1)); % left
fun2 = @(m2) (2/(gam+1))*(1+((gam-1)/2)*m2); % right
Mp2 = fzero(@(m2) fun1(m2)-fun2(m2), [.01 1])
pp1 = pg*(1+((gam-1)/2)*Mp2).^(-gam/(gam-1))
% check
(Ap1/At)^2 - (1/Mp2)*((2/(gam+1)*(1+((gam-1)/2)*Mp2))).^((gam+1)/(gam-1))
ans = 4.6185e-14
pg - pp1*(1+((gam-1)/2)*Mp2).^(gam/(gam-1))
ans = 0

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by