Seek Matlab Help in this problem

  • MATLAB
  • Thread starter qazinasir
  • Start date
  • Tags
    Matlab
In summary, the conversation discusses a code that calculates the vapor pressure of n-heptane using the SRK-EOS equation. The code involves assuming a pressure and checking if the results satisfy the error condition, if not, a new pressure is calculated and updated in a loop. The main question is how to update the previously assumed pressure with a new one.
  • #1
qazinasir
5
0
% Calculate the vapor Pressure of n-heptane using SRK-EOS
% P = RT / V - b - alpha*a / V(V-b)
R = 8.134e-3; % MPa m3 / mole.K
n = 0;
n = n+1;
for i=1:5
Pn = 1.6714; %(Assume Pressure)> this needs updating
Tr = 0.9;
Tc = 540.13; % K
Pc = 2.74; % Mpa;
T = Tr*Tc;
w = 0.350;
m = 0.480+1.574*w -0.176*w^2;
al=(1+m*(1-Tr^0.5))^2;
a = 0.42748*(((R*Tc)^2) /Pc);
b = 0.08664*(R*Tc / Pc);
% Z3 - Z2 + (A-B-B^2)Z-AB=0
A = (a*Pn*al)/(R*T)^2;
B = (b*Pn)/(R*T);
Zv=max(roots([1 -1 A-B-B^2 -A*B]));
Zl=min(roots([1 -1 A-B-B^2 -A*B]));
disp(Zv)
disp(Zl)
phiv(i)=exp((Zv -1)-log(Zv -B)-(A/B) *(log(Zv+B/Zv )));
phil(i)=exp((Zl -1)-log(Zl -B)-(A/B) *(log(Zl+B/Zl )));
Fv=Pn*phiv;
Fl=Pn*phil;
disp(phiv)
disp(phil);
disp(Fv);
disp(Fl);
Error=Fl-Fv;
if (Error < 10^-4);
Pnew=Pn;
else
P(n+1) =Pn * (phil/phiv);
Pn = P(n+1);
end
end
Basically in this code I am trying to assume a pressure 'Pn' to calculate the results which satisfy this relation (Error<10^-4) if this satisfy's then our assume pressure is right else if not then we use the relation P(n+1) = Pn*(Phil/Phiv) to caluclate another pressure and update the above pressure (previously assume) with this one. I have error with this and need advice please help
 
Physics news on Phys.org
  • #2
it's a very small chance people will read that much code and do that much thinking for you. Try to narrow down your specific theoretical or technical problem. Try debugging your code a little bit to chase the source down; you might even solve the problem if you spend some time trying to understand it before you ask.
 
  • #3
Basically in this code I am trying to assume a pressure 'Pn' to calculate the results which satisfy this relation (Error<10^-4) if this satisfy's then our assume pressure is right else if not then we use the relation P(n+1) = Pn*(Phil/Phiv) to caluclate another pressure and update the above pressure (previously assume) with this one. but this cycle of Assuming and error checking is perform in a loop (if i am not wrong ) . How to update the previously Assume pressure with new one. that's the main question
 

What is Matlab and how can it help me with my problem?

Matlab is a high-level programming language and interactive environment commonly used in scientific research and engineering. It can help you with your problem by providing powerful tools for data analysis, visualization, and simulation.

Can I get help with my specific problem in Matlab?

Yes, there are many resources available for seeking help with specific problems in Matlab. You can consult online forums, attend workshops or training sessions, or hire a professional Matlab programmer for personalized assistance.

How do I find someone who can help me with my Matlab problem?

There are several ways to find someone who can help you with your Matlab problem. You can ask colleagues or classmates for recommendations, search for Matlab experts online, or reach out to your university's computer science or engineering department for assistance.

What types of problems can I get help with in Matlab?

You can get help with a wide range of problems in Matlab, including data processing and analysis, image and signal processing, numerical computations, and creating visualizations and simulations. Matlab is a versatile tool that can be applied to various scientific and engineering fields.

Is seeking help in Matlab cheating?

No, seeking help in Matlab is not cheating. It is a common practice in the scientific community to collaborate and seek guidance from experts when facing complex problems. As long as you properly cite any external help you receive, seeking assistance in Matlab is a legitimate and ethical approach to problem-solving.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
272
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • Introductory Physics Homework Help
Replies
2
Views
732
Back
Top