Results 1 to 6 of 6

Math Help - Matlab: Newton-Raphson Method

  1. #1
    Member
    Joined
    Apr 2008
    Posts
    191

    Matlab: Newton-Raphson Method

    Hi guys, I need some help solving the following question using matlab:


    My Attempt:

    t_{2} is the time at which the object hits the ground (when the height =0, or the root/x-intercept of the graph).

    I have to use this Newton Raphson formula:

     <br />
x^k = x^{k-1} - \frac{f(x^{k-1})}{f'(x^{k-1})}<br />

    so here's my Matlab command:

    Code:
     
    theta=pi/4; v=10; g=9.81; a=0.1;
    n_itn=3;
    y(1)=0;
    for k=1:n_itn
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a)
    y'=diff(y)
    y(k+1)=y(k)-y(k)/y'(k)
    end
    
    But unfortunately I get the following error:

    Code:
    ??? Error: File: Q1.m Line: 6 Column: 3
    The expression to the left of the equals sign is not a valid target for an assignment.
    I don't understand what's the problem with line 6. Can anyone help?

    P.S.
    Just to have a confirmation I already tried to estimate the root by ploting y versus t and I think the root is around 1.41, here are my commands:

    Code:
     
    theta=pi/4; v=10;  g=9.81;   a=0.1;
    nfinal=2;
    t=1:0.01:nfinal;
    x=((1-exp(-a*t))/a)*v*cos(theta);
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a);
    plot(t,y,’+')
    Last edited by Roam; September 7th 2009 at 07:27 PM.
    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 Roam View Post
    Hi guys, I need some help solving the following question using matlab:


    My Attempt:

    t_{2} is the time at which the object hits the ground (when the height =0, or the root/x-intercept of the graph).

    I have to use this Newton Raphson formula:

     <br />
x^k = x^{k-1} - \frac{f(x^{k-1})}{f'(x^{k-1})}<br />

    so here's my Matlab command:

    Code:
     
    theta=pi/4; v=10; g=9.81; a=0.1;
    n_itn=3;
    y(1)=0;
    for k=1:n_itn
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a)
    y'=diff(y)
    y(k+1)=y(k)-y(k)/y'(k)
    end
    
    But unfortunately I get the following error:

    Code:
    ??? Error: File: Q1.m Line: 6 Column: 3
    The expression to the left of the equals sign is not a valid target for an assignment.
    I don't understand what's the problem with line 6. Can anyone help?

    P.S.
    Just to have a confirmation I already tried to estimate the root by ploting y versus t and I think the root is around 1.41, here are my commands:

    Code:
     
    theta=pi/4; v=10;  g=9.81;   a=0.1;
    nfinal=2;
    t=1:0.01:nfinal;
    x=((1-exp(-a*t))/a)*v*cos(theta);
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a);
    plot(t,y,+')
    diff only works on symbolic objects.

    You need to differentiate y (wrt x) yourself.

    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Apr 2008
    Posts
    191

    how do you define t?

    Quote Originally Posted by CaptainBlack View Post
    diff only works on symbolic objects.

    You need to differentiate y (wrt x) yourself.

    CB
    I still have another problem!

    Thanks for the hint, I differentiated it separately by creating a symbolic variable:

    Code:
     
    >> syms t
     
    >> f=((1-exp(-0.1*t))/0.1)*105.17-((9.81*t)/0.1)
     
    f =
     
    10517/10-10517/10*exp(-1/10*t)-981/10*t
     
     
    >> diff(f)
     
    ans =
     
    10517/100*exp(-1/10*t)-981/10

    This is my new code:

    Code:
     
    theta=pi/4; v=10; g=9.81; a=0.1;
    n_itn=3;
    y(1)=0;
    for k=1:n_itn
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a)
    z=10517/100*exp(-1/10*t)-981/10
    y(k+1)=y(k)-y(k)/z(k);
    end
    I used "z" to denote y' because for some reason matlab didn't accept "y'" in the code.

    Now I get this error:

    Code:
     
    ??? Undefined function or variable 't'.
    Error in ==> Untitled at 5
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a)
    I don't understand... how do I need to define "t"?



    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 Roam View Post
    I still have another problem!

    Thanks for the hint, I differentiated it separately by creating a symbolic variable:

    Code:
     
    >> syms t
     
    >> f=((1-exp(-0.1*t))/0.1)*105.17-((9.81*t)/0.1)
     
    f =
     
    10517/10-10517/10*exp(-1/10*t)-981/10*t
     
     
    >> diff(f)
     
    ans =
     
    10517/100*exp(-1/10*t)-981/10

    This is my new code:

    Code:
     
    theta=pi/4; v=10; g=9.81; a=0.1;
    n_itn=3;
    y(1)=0;
    for k=1:n_itn
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a)
    z=10517/100*exp(-1/10*t)-981/10
    y(k+1)=y(k)-y(k)/z(k);
    end
    I used "z" to denote y' because for some reason matlab didn't accept "y'" in the code.

    Now I get this error:

    Code:
     
    ??? Undefined function or variable 't'.
    Error in ==> Untitled at 5
    y=((1-exp(-a*t))/a)*((g/a)+v*sin(theta))-((g*t)/a)
    I don't understand... how do I need to define "t"?


    Assign it a value t=10 (or something like that) first.

    CB
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Member
    Joined
    Apr 2008
    Posts
    191
    Quote Originally Posted by CaptainBlack View Post
    Assign it a value t=10 (or something like that) first.

    CB

    I tried setting t=10 like you said & it's still not working and I keep getting errors.

    "??? Attempted to access y(2); index out of bounds because numel(y)=1.

    Error in ==> Untitled at 8
    y(k+1)=y(k)-y(k)/z(k);"
    Last edited by Roam; September 12th 2009 at 03:29 PM.
    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 Roam View Post
    I tried setting t=10 like you said & it's still not working and I keep getting errors.
    Then abandon the use of symbolics and define the functions:

    Code:
    >>g=9.81;alpha=0.1;theta=pi/4;v=10;
    >>
    >>ff=@(t) (1-exp(-alpha*t))/alpha*(g/alpha+v*sin(theta))-g*t/alpha;
    >>dff=@(t) exp(-alpha*t)*(sin(theta)*v+g/alpha)-g/alpha;
    >>
    >>t=10;                                                          
    >>t=t-ff(t)/dff(t)
    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Newton raphson method
    Posted in the Calculus Forum
    Replies: 5
    Last Post: April 4th 2011, 11:44 AM
  2. Newton Raphson method
    Posted in the Calculus Forum
    Replies: 4
    Last Post: May 24th 2010, 06:38 AM
  3. Newton-Raphson method
    Posted in the Calculus Forum
    Replies: 3
    Last Post: December 30th 2009, 07:13 AM
  4. Newton Raphson Method?????? HELP!
    Posted in the Calculus Forum
    Replies: 3
    Last Post: March 5th 2007, 09:37 AM
  5. Help- Newton - Raphson Method
    Posted in the Calculus Forum
    Replies: 3
    Last Post: July 12th 2006, 07:49 AM

Search Tags


/mathhelpforum @mathhelpforum