Results 1 to 3 of 3

Math Help - MATLAB interpolation

  1. #1
    Newbie
    Joined
    Oct 2009
    Posts
    24

    MATLAB interpolation

    So using the formula on this page Title
    i need to linearly interpolate a function... i have set up two arrays t=0:20 and tt=0:.1:20.... (ps. not allowed to use the matlab interpolation function) ...this is what i have written. obviously it is no good, but can someone further explain what i need to do or fix or point me in the right direciton? Thanks

    t=0:20;
    y=exp(-t/10).*cos(t);
    tt=0:.1:20;
    for i=1:floor(tt)
    yy(i)=y(i)+((y(i+1)-y(i))./(t(i+1)-t(i))).*(t-t(i))
    end

    i know that a point t on the curve in this case is equal to floor(tt(i))... how do i index this into y(_)
    Last edited by plopony; October 2nd 2009 at 09:51 AM.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    The "find" command might work for what you are trying to do. Below demonstrates finding the two indexes that bracket the value 2.5. Obviously it is a trivial example.

    Code:
    EDU>> x = [0 1 1 2 3 5 8 13 21]
    
    x =
    
         0     1     1     2     3     5     8    13    21
    
    EDU>> find(x<2.5,1,'last')
    
    ans =
    
         4
    
    EDU>> find(x>2.5,1,'first')
    
    ans =
    
         5
    
    EDU>>
    Regards Elbarto
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by plopony View Post
    So using the formula on this page Title
    i need to linearly interpolate a function... i have set up two arrays t=0:20 and tt=0:.1:20.... (ps. not allowed to use the matlab interpolation function) ...this is what i have written. obviously it is no good, but can someone further explain what i need to do or fix or point me in the right direciton? Thanks

    t=0:20;
    y=exp(-t/10).*cos(t);
    tt=0:.1:20;
    for i=1:floor(tt)
    yy(i)=y(i)+((y(i+1)-y(i))./(t(i+1)-t(i))).*(t-t(i))
    end

    i know that a point t on the curve in this case is equal to floor(tt(i))... how do i index this into y(_)
    Try this (warning - untested):

    Code:
    t=0:20;
    y=exp(-t/10).*cos(t);
    tt=0:.1:20;
    
    for i=1:length(tt)
        twrk=tt(i);
    
        ihi=max(find(t<=twrk))+1;
        if ihi>length(t);ihi=length(t);end
        ilo=ihi-1;
    
        yy(i)=y(ilo)+((y(ihi)-y(ilo))./(t(ihi)-t(ilo))).*(twrk-t(ilo))     
       
    end
    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Interpolation
    Posted in the Calculus Forum
    Replies: 3
    Last Post: September 17th 2010, 02:07 AM
  2. Matlab 3D Interpolation/Display
    Posted in the Math Software Forum
    Replies: 4
    Last Post: July 6th 2010, 06:25 AM
  3. Interpolation
    Posted in the Statistics Forum
    Replies: 3
    Last Post: February 9th 2010, 08:00 AM
  4. Interpolation of sin(x) with MATLAB
    Posted in the Math Software Forum
    Replies: 0
    Last Post: May 7th 2009, 03:59 AM
  5. Interpolation
    Posted in the Calculus Forum
    Replies: 0
    Last Post: April 2nd 2009, 02:16 PM

Search Tags


/mathhelpforum @mathhelpforum