Evaluate function handle with "for"
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Sensors and Transducers dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!