Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Finding roots for a function

Subject: Finding roots for a function

From: Levi

Date: 14 Dec, 2011 00:35:09

Message: 1 of 4

I am relatively new to matlab and I am unsure how to find the roots for the function
P=(r*temp/vhat)*(1+(BT/vhat)+(CT/vhat^2)) . Which is the cubic virial equation of state. I have defined my constants using

r=8.3136;
temp=493.9;
Tc=593.9;
Pc=40.83599e05;
a=(0.4275*(r^2)*(Tc^2.5))/(Pc);
b=(0.08664*r*Tc)/(Pc);
BT=b-(a/(r*temp^1.5));
CT=b*(b+a/(r*temp^1.5));

I need to guess a Pressure and solve for vhat to get my answer but I do not know how to program matlab to accomplish this.

Any help is appreciated.

Thanks!

Subject: Finding roots for a function

From: dpb

Date: 14 Dec, 2011 00:40:50

Message: 2 of 4

On 12/13/2011 6:35 PM, Levi wrote:
> I am relatively new to matlab and I am unsure how to find the roots for
> the function
> P=(r*temp/vhat)*(1+(BT/vhat)+(CT/vhat^2)) . Which is the cubic virial
...

> I need to guess a Pressure and solve for vhat to get my answer but I do
> not know how to program matlab to accomplish this.
...

doc fzero

--

Subject: Finding roots for a function

From: Nasser M. Abbasi

Date: 14 Dec, 2011 00:41:09

Message: 3 of 4

On 12/13/2011 6:35 PM, Levi wrote:
> I am relatively new to matlab and I am unsure how to find the roots for the function
> P=(r*temp/vhat)*(1+(BT/vhat)+(CT/vhat^2)) . Which is the cubic virial equation of state. I have defined my constants using
>
> r=8.3136;
> temp=493.9;
> Tc=593.9;
> Pc=40.83599e05;
> a=(0.4275*(r^2)*(Tc^2.5))/(Pc);
> b=(0.08664*r*Tc)/(Pc);
> BT=b-(a/(r*temp^1.5));
> CT=b*(b+a/(r*temp^1.5));
>
> I need to guess a Pressure and solve for vhat to get my answer but I do not know how to program matlab to accomplish this.
>
> Any help is appreciated.
>
> Thanks!


---------------------
r=8.3136;
temp=493.9;
Tc=593.9;
Pc=40.83599e05;
a=(0.4275*(r^2)*(Tc^2.5))/(Pc);
b=(0.08664*r*Tc)/(Pc);
BT=b-(a/(r*temp^1.5));
CT=b*(b+a/(r*temp^1.5));
  
syms vhat
P=(r*temp/vhat)*(1+(BT/vhat)+(CT/vhat^2));

double(solve(P,vhat))

ans =
    0.00031679
    0.00026002
-------------------

or try fsolve() if you want numerical solution.

--Nasser

Subject: Finding roots for a function

From: Roger Stafford

Date: 14 Dec, 2011 01:40:10

Message: 4 of 4

"Levi" wrote in message <jc8qvt$lb6$1@newscl01ah.mathworks.com>...
> P=(r*temp/vhat)*(1+(BT/vhat)+(CT/vhat^2)) . Which is the cubic virial equation ....
- - - - - - - - - - - -
  Once you know P, your equation becomes a cubic polynomial in 1/vhat and can be solved for all three possible roots of 1/vhat using matlab's 'roots' function, from which you can then easily find vhat. An advantage of doing things this way is that you will always get all possible solutions (even though some might be complex-valued.)

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us