1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Interpolation in matlab

  1. Oct 25, 2009 #1
    1. The problem statement, all variables and given/known data

    If i have an interpolation formula, say:


    where i=0 to n
    when i=0, we have: y(t0)=0.

    How would i write a code to find y(ti)?

    2. Relevant equations

    3. The attempt at a solution

    function y=examp(a,b,n)
    for i=1:n+1
    for j=1:i+1

    and now im stuck because i dont know how write a code that uses the previous value of y to compute the next value of y.
  2. jcsd
  3. Nov 3, 2009 #2
    Before the first loop, I would set up the y's(actually, it would be faster for your code to init the t's to zeros to, but unless n is very large it shouldn't matter):

    y = zeros(n+1,1)

    Then in the loop it would be something like
    y(j) = 3 + sum( y(1:j-1).*(1:j-1) )

    the .* does an element-wise product
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook