Evaluate function handle with "for"
이전 댓글 표시
I want to write a code to obtain the partial derivates of a function R^n ->R given by the user. For that, the parameters in which I evaluate the function change according to the variable that is being derivated.
I thought about using a FOR loop, but I don't know how to write the code so it will chance the values where the function is evaluated according to the variable.
For example, the code for the first two varibles would be
parcial_1 = (feval(f,x0+h,y0)-feval(f,x0-h,y0))/(2*h);
parcial_2 = (feval(f,x0,y0+h)-feval(f,x0,y0-h))/(2*h);
The full code I have is this
x0 = 2;
y0=2;
h = 0.01;
f=input('Input the function: ');
num_variables=nargin(f);
disp(num_variables);
for i=1:num_variables
parcial_i=(feval(f,x0+h,y0)-feval(f,x0-h,y0))/(2*h);
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Sensors and Transducers에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!