Results 1 to 10 of 10

Math Help - Intro to Matlab help

  1. #1
    Junior Member
    Joined
    Jan 2010
    Posts
    38

    Intro to Matlab help

    I need to setup an M-file called nmoles that requires two vector inputs - the mass (m) and molecular weight (MW) - and returns the corresponding number of moles.

    n = m/MW

    can anyone help me please! thanks
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    I need to setup an M-file called nmoles that requires two vector inputs - the mass (m) and molecular weight (MW) - and returns the corresponding number of moles.

    n = m/MW

    can anyone help me please! thanks
    The general form of a function .m file is:

    Code:
    funtion n=nmoles(m, MW)
       n=... ;
    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    This really didn't help me...can you please explain further.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    This really didn't help me...can you please explain further.
    Replace the ... by m/MW and that is the content of the .m file.

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    I typed it in as you suggested:
    function n=nmoles (m, MW)
    n=m/MW

    But when i type it in the command window i get the following error:

    ??? Input argument "MW" is undefined.
    Error in ==> nmoles at 2
    n=m/MW


    any suggestions?
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    you need to call the function from another mfile or at the command line after you finish defining the function:

    eg

    Code:
    nmoles(1,1)
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    Quote Originally Posted by elbarto View Post
    you need to call the function from another mfile or at the command line after you finish defining the function:

    eg

    Code:
    nmoles(1,1)

    that worked! thank you!

    how about it if want to test this function out. Using masses from 1 to 10g with the coumpound benzene that has a MW of 78.115g/mol.

    would the following code be correct:
    nmoles (1:10, 78.115)?
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    I think that was what i was looking for. Now i need to show the MW in a 10 x 3 matrix for 3 different compounds (benzene = 78.115g/mol, ethyl alcohol = 46.07 g/mol, and r134a = 102.3 g/mol).

    I only know how to put make it a 1 x 10 matrix.
    ex. nmoles (1:10, 78.115), nmoles (1:10, 46.07), nmoles (1:10. 102.3).
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Junior Member
    Joined
    Jan 2010
    Posts
    38
    I tried the following in Matlab:
    Benzene = nmoles (1:10, 78.115);
    Ethyl_Alcohol = nmoles (1:10, 46.07);
    R134a = nmoles (1:10, 102.3);
    x = [Benzene', Ethyl_Alcohol', R134a']

    x =
    0.0128 0.0217 0.0098
    0.0256 0.0434 0.0196
    0.0384 0.0651 0.0293
    0.0512 0.0868 0.0391
    0.0640 0.1085 0.0489
    0.0768 0.1302 0.0587
    0.0896 0.1519 0.0684
    0.1024 0.1736 0.0782
    0.1152 0.1954 0.0880
    0.1280 0.2171 0.0978

    Does this seem like the correct code?
    Also, it is asking to put the function in meshgrid...no clue here, any suggestions?
    Follow Math Help Forum on Facebook and Google+

  10. #10
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by lvelazquez83 View Post
    that worked! thank you!

    how about it if want to test this function out. Using masses from 1 to 10g with the coumpound benzene that has a MW of 78.115g/mol.

    would the following code be correct:
    nmoles (1:10, 78.115)?
    Why are you asking? Just run it and see.

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Intro to Integrals
    Posted in the Calculus Forum
    Replies: 4
    Last Post: January 8th 2010, 12:07 AM
  2. intro analysis help
    Posted in the Differential Geometry Forum
    Replies: 3
    Last Post: September 7th 2009, 05:39 PM
  3. Intro to Analysis
    Posted in the Differential Geometry Forum
    Replies: 2
    Last Post: September 7th 2009, 05:54 AM
  4. Intro Calc HW
    Posted in the Calculus Forum
    Replies: 1
    Last Post: April 3rd 2008, 05:24 AM
  5. Intro Calc
    Posted in the Calculus Forum
    Replies: 4
    Last Post: June 22nd 2007, 12:02 PM

Search Tags


/mathhelpforum @mathhelpforum