Matlab second derivative approximation

Click For Summary
SUMMARY

The discussion focuses on approximating the second derivative using MATLAB, specifically addressing an error encountered in the function f9. The user initially attempted to compute the second derivative using a finite difference method but faced an "undefined input argument" error due to incorrect indexing in the function call. The solution provided clarifies that the correct syntax should be f9(x(i), y(j)) instead of f9, ensuring proper input to the function.

PREREQUISITES
  • Understanding of MATLAB programming and syntax
  • Familiarity with finite difference methods for numerical differentiation
  • Knowledge of function definitions and variable scope in MATLAB
  • Basic concepts of meshgrid and surface plotting in MATLAB
NEXT STEPS
  • Explore MATLAB's numerical differentiation techniques
  • Learn about error handling and debugging in MATLAB
  • Investigate advanced surface plotting functions in MATLAB
  • Study the implications of finite difference methods on numerical stability
USEFUL FOR

Mathematics students, MATLAB users, and engineers interested in numerical methods for partial derivatives and surface visualization.

splelvis
Messages
10
Reaction score
0
clear all;
nx=50;
ny=30;
hx=pi/nx;
x=linspace(0,pi,nx+1);
y=linspace(0,pi,ny+1);
x_plus_h=x+hx.*ones(1,nx+1);
x_minus_h=x-hx.*ones(1,nx+1);
for i=1:nx+1
for j=1:ny+1
f_xx(j,i)=(f9(x_plus_h(i),y(j))-2*f9+f9(x_minus_h(i),y(j)))./(hx.^2);
end;
end;
[xx,yy]=meshgrid(x,y);
surf(xx,yy,f_xx);
title('partial derivative w.r.t.xx')
,

and the other new document,f9,
function l=f9(x,y)
l=exp(sin(x-y));and then the system said have error,

? Input argument "x" is undefined.

Error in ==> f9 at 2
l=exp(sin(x-y));
Error in ==> partial_derivxx at 11
f_xx(j,i)=(f9(x_plus_h(i),y(j))-2*f9+f9(x_minus_h(i),y(j)))./(hx.^2);where should i corrected to make it work?
thanks

anyone can help
 
Last edited:
Physics news on Phys.org
i have find my error,
f9should be f9(x(i),y(j))
 

Similar threads

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