I can't get input a trigonometric expression
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Merve Basak Uzun
el 25 de Mayo de 2022
clc;
b = input("Enter the initial limit value of the definite integral: ");
a = input("Enter the limit value that terminates the definite integral: ");
n = input("Enter the value of N: ");
h=(b-a)/n;
sum=0;
u = input("Enter the function to be integrated: ");
f=@(x) u;
for i=1:1:n-1
sum= sum + f(a+i*h);
end
result = h/2*(f(a)+f(b)+2*sum);
fprintf('%f',result);
It gives an error because of the "u" input. It throws an error when "u" writes a trigonometric expression to the input. I need your help, thanks.
0 comentarios
Respuesta aceptada
Voss
el 25 de Mayo de 2022
u = input('Enter the function to be integrated: ','s');
f = str2func(['@(x)' u]);
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!