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:
Matlab Problem with Ideal Gas Law

Subject: Matlab Problem with Ideal Gas Law

From: Trent Renier

Date: 27 Jan, 2010 03:32:10

Message: 1 of 5

I am working on a problem for engineering with MATLAB and the ideal
gas law but am having trouble. This is my 3rd time using MATLAB so
bare with me.

here are the two problems, A seems to be working fine, its B im having
trouble with.

Calculate T with:
a. 10 values of pressure from 0 bar to 400 bar for volume 1L
b. 10 values of volume from .1L to 10L for a pressure of 220 bar.

Heres my code:
% --- INPUTS ---
Pa=linspace(0,400,10) % pressure for part a - measured in bar
Va=1 % volume for part a - measured in L
n=2 % number of moles
R=.08314472 % ideal gas constant - measured in L bar/K mol
a=5.536 % measured in L^2bar/mol^2
b=.03049 % memasured in L/mol
Pb=220 % pressure for part b - measured in bar
Vb=[.1:1.1:10]

% --- CALCULATIONS ---
Ta=((Pa+(n^2*a/Va^2))*(Va-(n*b)))/(n*R) % Temperature calculation for
part a
Tb=((Pb+(n^2*a/Vb^2))*(Vb-(n*b)))/(n*R) % Temperature calculation for
part b


Thanks in advance for the help guys!

Subject: Matlab Problem with Ideal Gas Law

From: Trent Renier

Date: 27 Jan, 2010 03:33:58

Message: 2 of 5

On Jan 26, 10:32 pm, Trent Renier <lildevil111...@gmail.com> wrote:
> I am working on a problem for engineering with MATLAB and the ideal
> gas law but am having trouble. This is my 3rd time using MATLAB so
> bare with me.
>
> here are the two problems, A seems to be working fine, its B im having
> trouble with.
>
> Calculate T with:
> a. 10 values of pressure from 0 bar to 400 bar for volume 1L
> b. 10 values of volume from .1L to 10L for a pressure of 220 bar.
>
> Heres my code:
> % --- INPUTS ---
> Pa=linspace(0,400,10) % pressure for part a - measured in bar
> Va=1 % volume for part a - measured in L
> n=2 % number of moles
> R=.08314472 % ideal gas constant - measured in L bar/K mol
> a=5.536 % measured in L^2bar/mol^2
> b=.03049 % memasured in L/mol
> Pb=220 % pressure for part b - measured in bar
> Vb=[.1:1.1:10]
>
> % --- CALCULATIONS ---
> Ta=((Pa+(n^2*a/Va^2))*(Va-(n*b)))/(n*R) % Temperature calculation for
> part a
> Tb=((Pb+(n^2*a/Vb^2))*(Vb-(n*b)))/(n*R) % Temperature calculation for
> part b
>
> Thanks in advance for the help guys!

Sorry for not stating my error, im gettin an error that my matrix must
be square for the first part of the B equation. I dont know how to fix
this..

Subject: Matlab Problem with Ideal Gas Law

From: dpb

Date: 27 Jan, 2010 03:42:38

Message: 3 of 5

Trent Renier wrote:
...

> Sorry for not stating my error, im gettin an error that my matrix must
> be square for the first part of the B equation. I dont know how to fix
> this..

Look at ./, .*, etc., ...

Consider what * or / mean in matrix terms (look their description up as
well)...

--

Subject: Matlab Problem with Ideal Gas Law

From: Trent Renier

Date: 27 Jan, 2010 05:01:28

Message: 4 of 5

On Jan 26, 10:42 pm, dpb <n...@non.net> wrote:
> Trent Renier wrote:
>
> ...
>
> > Sorry for not stating my error, im gettin an error that my matrix must
> > be square for the first part of the B equation. I dont know how to fix
> > this..
>
> Look at  ./, .*, etc., ...
>
> Consider what * or / mean in matrix terms (look their description up as
> well)...
>
> --

I have read through that prevously and understand the dot functions
but i just dont grasp where they go or how to make it all work
together.

Subject: Matlab Problem with Ideal Gas Law

From: dpb

Date: 27 Jan, 2010 05:16:34

Message: 5 of 5

Trent Renier wrote:
> On Jan 26, 10:42 pm, dpb <n...@non.net> wrote:
>> Trent Renier wrote:
>>
>> ...
>>
>>> Sorry for not stating my error, im gettin an error that my matrix must
>>> be square for the first part of the B equation. I dont know how to fix
>>> this..
>> Look at ./, .*, etc., ...
>>
>> Consider what * or / mean in matrix terms (look their description up as
>> well)...
>>
>> --
>
> I have read through that prevously and understand the dot functions
> but i just dont grasp where they go or how to make it all work
> together.

You need them where you want element-by-element operations as opposed to
matrix manipulations...

--

Tags for this Thread

No tags are associated with 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