Interpolation Formula in MATLAB | Solving for y(ti) with Code Example

Click For Summary
SUMMARY

The discussion focuses on implementing an interpolation formula in MATLAB to compute values of y(ti) using a defined recursive relationship. The formula is given as y(t_i) = 3 + h * Σ(j=1 to i) j * y(t_j), where h is calculated as (a+b)/n and ti is defined as i*h. The provided MATLAB code initializes an array for y values and iterates through the indices to compute each y(ti) based on previous values. The key challenge identified is effectively using prior computed values of y to derive subsequent values within the loop.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with interpolation methods and recursive formulas
  • Knowledge of element-wise operations in MATLAB
  • Basic concepts of numerical methods for solving equations
NEXT STEPS
  • Study MATLAB array initialization and manipulation techniques
  • Learn about recursive algorithms in numerical methods
  • Explore MATLAB's built-in functions for summation and element-wise operations
  • Investigate advanced interpolation techniques in MATLAB
USEFUL FOR

This discussion is beneficial for students and professionals in engineering, mathematics, and computer science who are working with numerical methods and interpolation in MATLAB.

sara_87
Messages
748
Reaction score
0

Homework Statement



If i have an interpolation formula, say:

y(t_i)=3+h\sum^i_{j=1}jy(t_j)

where i=0 to n
h=(a+b)/n
ti=i*h
and
when i=0, we have: y(t0)=0.

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

Homework Equations





The Attempt at a Solution



function y=examp(a,b,n)
h=(a+b)/n
for i=1:n+1
t(i)=(i-1)*h
for j=1:i+1

and now I am stuck because i don't know how write a code that uses the previous value of y to compute the next value of y.
 
Physics news on Phys.org
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
 

Similar threads

Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K