Results 1 to 7 of 7

Math Help - MATLAB Help?

  1. #1
    Junior Member
    Joined
    Jan 2009
    Posts
    27

    Exclamation MATLAB Help?

    Hi all,

    I am having trouble with user-defined functions in matlab.

    I want to add up 'n' numbers in a summation for a function.

    The equation, without values plugged in, is this:
    (It is about equivalence resistance)

    1/REQ = 1/r1 + 1/r2 + 1/r3 + 1/r4 + 1/r5 +....+ 1/rn

    You get the point.

    So Here is my work for matlab:

    Function:

    function [REQ] = req(r)
    req=1/sum(1./r);

    return

    And this is my script file:

    req_1=req(50,75,300,60,500,180,200)

    The seven inputs being what needs to go into the function.

    Thanks for any help!
    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 dillonmhudson View Post
    Hi all,

    I am having trouble with user-defined functions in matlab.

    I want to add up 'n' numbers in a summation for a function.

    The equation, without values plugged in, is this:
    (It is about equivalence resistance)

    1/REQ = 1/r1 + 1/r2 + 1/r3 + 1/r4 + 1/r5 +....+ 1/rn

    You get the point.

    So Here is my work for matlab:

    Function:

    function [REQ] = req(r)
    req=1/sum(1./r);

    return

    And this is my script file:

    req_1=req(50,75,300,60,500,180,200)

    The seven inputs being what needs to go into the function.

    Thanks for any help!
    Your function as defined has one argument but you call it with seven. Try:

    req_1=req([50,75,300,60,500,180,200])

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Junior Member
    Joined
    Jan 2009
    Posts
    27
    Ok, but my function needs to be defined for an infinite number of inputs, is there a way that I can do that?

    I want to be able to input 1 variable, or 50 without changing the function.

    Thanks
    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 dillonmhudson View Post
    Ok, but my function needs to be defined for an infinite number of inputs, is there a way that I can do that?

    I want to be able to input 1 variable, or 50 without changing the function.

    Thanks
    You input one variable which is a vector with however many elements you require. Which you would see if you looked at the sample calling code I gave you.

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Junior Member
    Joined
    Jan 2009
    Posts
    27
    Ok well here is my error that I get:


    Error in ==> req at 3
    req=1/sum(1./r);

    ??? Output argument "REQ" (and maybe others) not assigned during call to "/u/m152_806/dillonmhudson91/EngrMath/Gilat/c6/g188x15/req.m>req".

    Error in ==> g188x15 at 6
    req_1=req([50,75,300,60,500,180,200]);
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by dillonmhudson View Post
    Ok well here is my error that I get:


    Error in ==> req at 3
    req=1/sum(1./r);

    ??? Output argument "REQ" (and maybe others) not assigned during call to "/u/m152_806/dillonmhudson91/EngrMath/Gilat/c6/g188x15/req.m>req".

    Error in ==> g188x15 at 6
    req_1=req([50,75,300,60,500,180,200]);
    Matlab is case sensitive req and REQ are different variables:

    Code:
    function REQ = req(r)
    REQ=1/sum(1./r);
    
    return
    should work (the return is redundant)

    CB
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Junior Member
    Joined
    Jan 2009
    Posts
    27
    Wow, case-sensitive... Never would have thought of that.

    Thanks a lot buddy!
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Matlab help
    Posted in the Math Software Forum
    Replies: 1
    Last Post: February 11th 2010, 02:59 AM
  2. Matlab FFT Help
    Posted in the Math Software Forum
    Replies: 0
    Last Post: June 3rd 2009, 12:48 PM
  3. help about ODE in matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 31st 2009, 03:10 AM
  4. Matlab
    Posted in the Math Software Forum
    Replies: 0
    Last Post: November 6th 2008, 08:46 AM
  5. Matlab
    Posted in the Calculus Forum
    Replies: 3
    Last Post: August 20th 2008, 10:39 PM

Search Tags


/mathhelpforum @mathhelpforum