Simple matlab interpolation help

  • Context: MATLAB 
  • Thread starter Thread starter JXPES
  • Start date Start date
  • Tags Tags
    Interpolation Matlab
Click For Summary
SUMMARY

The discussion centers on a MATLAB interpolation method using a for loop and if statement to calculate values based on a function f(x) that increases with x. The user initially encountered errors beyond the fourth iteration due to not considering the order of intervals in their calculations. After addressing this oversight, the user successfully resolved the issue, indicating the importance of interval management in iterative calculations.

PREREQUISITES
  • Understanding of MATLAB programming language
  • Familiarity with interpolation techniques
  • Knowledge of control structures such as loops and conditional statements
  • Basic concepts of function behavior and monotonicity
NEXT STEPS
  • Explore MATLAB's built-in interpolation functions such as interp1
  • Learn about error handling in MATLAB to manage iteration issues
  • Investigate advanced interpolation methods like spline interpolation
  • Study the implications of function monotonicity on numerical methods
USEFUL FOR

MATLAB programmers, data analysts, and anyone involved in numerical methods or interpolation techniques seeking to enhance their coding practices and problem-solving skills.

JXPES
Messages
2
Reaction score
0
suppose I have a function f(x) which I know increases as x.

I'm trying to combine a for loop and if statement

x(1)=a;
x(2)=b;
x(3)=(a+b)/2;

for i=3:n
if f(x(i)) > A
x(i+1) = (x(i-2)+x(i))/2;
else
x(i+1) = (x(i-1)+x(i))/2
end
end

this method works for x(4), the rest come with errors! Am I missing something obvious? Thanks.
 
Physics news on Phys.org
never mind. worked it out- the order of the intervals had to be considered
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K