Results 1 to 8 of 8

Math Help - Matlab not returning variable as intended

  1. #1
    Newbie
    Joined
    Apr 2010
    Posts
    5

    Matlab not returning variable as intended

    I know this is a super simple problem that has been discussed before but I cannot find the answer for the life of me.
    All I want is for this program to output the variable as Y and have it correctly place it in the workspace as Y.

    Code:
    function [y] = stress(Ri,Ro,R,Delta,E)
    %stress = stress(Ri,Ro,R,Delta,E)
    
    y = Delta*E/R*1/((R^2+Ri^2)/(R^2-Ri^2)+(R^2+Ro^2)/(R^2-Ro^2));
    
    end
    What am I doing wrong?
    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 canyon289 View Post
    I know this is a super simple problem that has been discussed before but I cannot find the answer for the life of me.
    All I want is for this program to output the variable as Y and have it correctly place it in the workspace as Y.

    Code:
    function [y] = stress(Ri,Ro,R,Delta,E)
    %stress = stress(Ri,Ro,R,Delta,E)
    
      y = Delta*E/R*1/((R^2+Ri^2)/(R^2-Ri^2)+(R^2+Ro^2)/(R^2-Ro^2));
    
    end
    What am I doing wrong?
    Where is this function? It should be a function in a file called stress.m (and on the matlab path) or in the script file (I think). It cannot be a sub-function in another .m file.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Apr 2010
    Posts
    5
    It's a function file called stress.m, It's not a sub function of anything
    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 canyon289 View Post
    It's a function file called stress.m, It's not a sub function of anything
    Exactly what are the symptoms of it not doing what you expect.

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Newbie
    Joined
    Apr 2010
    Posts
    5
    Referring to the attached screenshot

    The output of the function is saved as ANS when I want it saved as Y.
    See how I inputted a variable for 1, ran my program and it didn't change the value of Y but rather added another scalar named ANS

    Thanks for you help
    Attached Thumbnails Attached Thumbnails Matlab not returning variable as intended-matlab.png  
    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 canyon289 View Post
    Referring to the attached screenshot

    The output of the function is saved as ANS when I want it saved as Y.
    See how I inputted a variable for 1, ran my program and it didn't change the value of Y but rather added another scalar named ANS

    Thanks for you help
    y= stress(Ri,Ro,R,Delta,E)

    CB
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Newbie
    Joined
    Apr 2010
    Posts
    5
    I don't understand. Do I put that in my function file somewhere? Sorry I'm very new to this.
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by canyon289 View Post
    I don't understand. Do I put that in my function file somewhere? Sorry I'm very new to this.
    no you put it in the command line or top level script, with the input variable assigned to the values you want, or just use numeric values.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Replies: 4
    Last Post: January 1st 2012, 09:25 PM
  2. matlab global variable
    Posted in the Math Software Forum
    Replies: 1
    Last Post: October 19th 2010, 03:06 AM
  3. Word problems (pun intended)
    Posted in the Algebra Forum
    Replies: 4
    Last Post: November 11th 2009, 03:19 PM
  4. Check please! (pun intended)
    Posted in the Math Topics Forum
    Replies: 1
    Last Post: April 9th 2009, 11:08 AM
  5. Help: Variable gain in Matlab
    Posted in the Math Software Forum
    Replies: 1
    Last Post: September 11th 2008, 02:15 PM

Search Tags


/mathhelpforum @mathhelpforum