Please proofread for a newbie :)

조회 수: 1 (최근 30일)
Hannah
Hannah 2011년 4월 1일
Hi, I am having so much trouble with matlab, this is what I have been trying:
function P=PR(V);
%Peng-Robinson EOS
%used to calculate vg and vl
R=8.314;
T=313.15;
b=5.63e-5;
a=1.1188;
P=1.3e6;
P=((R*T)./(V-b))-(a./(V*(V+b)+(b*(V-b))));
end
and then i do:
fsolve(@PR,1)
as I am trying to solve for V
it gives an answer that I know is not right, as I had the m-file working at uni today and now at home it just does not work. Any help or advice would be great, thanks
  댓글 수: 1
Jan
Jan 2011년 4월 1일
Some advice: 1. Use code formatting in your question to improve readability (see: http://www.mathworks.com/matlabcentral/answers/help/markup ). Readers are more likely to answer, if they see, that you spend time to formulate the question as clear as possible. 2. If you know, that result is not correct, please post the correct value in addition! How should we find the error without knowing the correct result?! 3. "It does not work" is a magic keyword: Whenever this appears in a question, it is most likely impossible to create a meaningful answer. We cannot guess, what the problem is, if you do not describe it with all necessary details -- except for walter, who obviously owns a magic crystal ball :-)

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

채택된 답변

Jan
Jan 2011년 4월 1일
"fsolve(@PR, 1)" solves the equation "P=((R*T)./(V-b))-(a./(V*(V+b)+(b*(V-b))))" such that P==0 using the initial value V==1. Do you want to do this?
It worked in the University and now it does not calculate the correct answer? This would be very helpful: Then the error is inside the modifications you have inserted in between! Or the command FSOLVE of one of the computers is broken - but this is less likely.
  댓글 수: 1
Hannah
Hannah 2011년 4월 2일
Thank you for your advice! I suppose I firstly need to modify it because I know my P, so I would need to subtract it from the equation such that it does equal 0. I have seen this done, in the FSOLVE part, rather than in the mfile - is this correct. Also, the correct answers were 0.0022 and 9.268e-5. There should also be a third but it is a nonsense answer. I don't think I changed it at all between campus and here except for how I am using FSOLVE command. I really appreciate your rapid response, and knowing how to ask questions better should help too.
Would it be something like
P=1e6
fsolve(@PR-P,1)
? Thanks!

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

추가 답변 (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