Using fsolve - solve for multiple variables using one input

I'm not new to Matlab, but I am quite bad at it. I need to run an optimization problem on the general shock wave equations and I am stuck. So, I have the 3 conservation equations (shown below as fmass, fmom, fen1, and fen2). fen2 is just another equation to solve for change in enthalpy. My problem is I have 4 unknowns: P2, rho2, u2, and DeltaH, but only one input (P). Here, P is an initial guess for P2. What I need is to give the function one input and have it solve for the 4 unknowns. It will do so when the DeltaH from fe1 = DeltaH from fen2. I hope this makes sense. The most important thing here is to find the proper DeltaH using ONLY my initial guess of P2. I'm not quite sure how to do this; like I said, I'm not very good at this. Here is the function code I have so far (I attached the file as well):
function F = deltah(P)
% The vector P is a vector of the unknowns in these equations, i.e. P2
rho1 = 2.3916; %kg/m3
P1 = 78600; %Pa
T1 = 295; %K
u1 = 372.3516; %m/s
kappa = 1.28641936633961e-05;
beta = 0.0034;
cp = 778.253929133643;
cv = 666.318314616417;
% fmass = conservation of mass equation
fmass = X(3) - (rho1*u1)/X(2);
% fmom = conservation of momentum equation
fmom = X(1) - P1 + (((rho1^2)*(u1^2))/X(2)) - rho1*(u1^2);
% fen1 = conservation of energy equation in terms of u and rho
fen1 = X(4) - (u1^2)/2 + (((rho1^2)*(u1^2))/(2*(X(2)^2)));
% fen2 = conservation of energy equation in terms of thermodynamic
% coefficients cp, cv, beta, the density rho, and pressure
fen2 = X(4) - (X(1)-P1)*(cv*kappa/beta) + (cp/beta)*(ln(X(2)/rho1));
F = [fmass; fmom; fen1; fen2];
end
Update: I thought this worked when I gave initial guesses for everything, but it doesn't. I'm really stuck now.

4 件のコメント

Torsten
Torsten 2018 年 3 月 20 日
So you are given rho1, P1, T1, u1 and P2 and you try to determine rho2, T2 and u2 ?
What are the three equations to get the unknowns ? How do you call the nonlinear solver "fsolve" ?
Best wishes
Torsten.
PATRICK WAYNE
PATRICK WAYNE 2018 年 3 月 20 日
No, I have values for rho1, u1, P1, and u1. I want to guess a value of P2 and iterate over the 4 equations until DeltaH from fen1 equals DeltaH from fen2. Right now I'mn calling fsolve by:
[Soln] = fsolve(@deltah,X,options)
where X is a vector of the 4 unknowns [P2; rho2; u2; DeltaH]. I've modified the code such that all of the unknowns are now P2 = X(1), rho2 = X(2), u2 = X(3), and Del;taH = X(4).
Torsten
Torsten 2018 年 3 月 21 日
編集済み: Torsten 2018 年 3 月 21 日
And what problems do you encounter if you add initial values for X0 and run the following code ?
X0 = ...;
[Soln] = fsolve(@deltah,X0,options)
function F = deltah(X)
% The vector P is a vector of the unknowns in these equations, i.e. P2
rho1 = 2.3916; %kg/m3
P1 = 78600; %Pa
T1 = 295; %K
u1 = 372.3516; %m/s
kappa = 1.28641936633961e-05;
beta = 0.0034;
cp = 778.253929133643;
cv = 666.318314616417;
% fmass = conservation of mass equation
fmass = X(3) - (rho1*u1)/X(2);
% fmom = conservation of momentum equation
fmom = X(1) - P1 + (((rho1^2)*(u1^2))/X(2)) - rho1*(u1^2);
% fen1 = conservation of energy equation in terms of u and rho
fen1 = X(4) - (u1^2)/2 + (((rho1^2)*(u1^2))/(2*(X(2)^2)));
% fen2 = conservation of energy equation in terms of thermodynamic
% coefficients cp, cv, beta, the density rho, and pressure
fen2 = X(4) - (X(1)-P1)*(cv*kappa/beta) + (cp/beta)*(ln(X(2)/rho1));
F = [fmass; fmom; fen1; fen2];
end
PATRICK WAYNE
PATRICK WAYNE 2018 年 3 月 21 日
I do get values when I assign guesses for all four inputs, but the results are not valid, at least I don't think so. I'll have to try and figure out how to confirm them, but if they are good then all I need to do is figure out how to put this in a loop.

サインインしてコメントする。

回答 (0 件)

質問済み:

2018 年 3 月 16 日

コメント済み:

2018 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by