Please help!!!!First input must be a function handle

2 visualizaciones (últimos 30 días)
Alex Cruz
Alex Cruz el 13 de Mayo de 2018
Editada: Walter Roberson el 13 de Mayo de 2018
this is my code:
syms x;
a = -5;
b = 5;
f = 1/(1+x^2);
n=57;
h = (b-a)/(2*n);
k = linspace(a,b,2*(n+1));
s = arrayfun(f,k);
I want to aplly f to all the elements of k but it gives a error "First input must be a function handle"
Thx for your time

Respuesta aceptada

Stephan
Stephan el 13 de Mayo de 2018
Editada: Stephan el 13 de Mayo de 2018
Hi
try this:
syms x;
a = -5;
b = 5;
f = @(x)1/(1+x^2);
n=57;
h = (b-a)/(2*n);
k = linspace(a,b,2*(n+1));
s = arrayfun(f,k);
Best regards
Stephan
  2 comentarios
Alex Cruz
Alex Cruz el 13 de Mayo de 2018
it worked, thanks a lot
Stephan
Stephan el 13 de Mayo de 2018
Hi Alex,
nice. Please accept helpful answers in order to help people with similar problems finding helpful answers.
Best regards
Stephan

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by