Using fsolve - solve for multiple variables using one input
Show older comments
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 Comments
Torsten
on 20 Mar 2018
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
on 20 Mar 2018
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
on 21 Mar 2018
Answers (0)
Categories
Find more on Structural Mechanics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!