Write a script that prompts the user to input a function, f(x),
Mostrar comentarios más antiguos
Write a script that prompts the user to input a function, f(x), and the limits of integration, a and b. The script should approximate the integral of the function from a to b, using the Trapezoid Rule. The script should also generate a plot of the function AND the piecewise-linear approximation to the function used in the Trapezoid Rule.
this is what i have soo far
clc,clear all, close all
f=str2func(['@(x)' input('Enter f(x):','s')]);
x=linspace(a,b,N);
N=input('define n=');
a=input('insert lower limit=');
b=input('insert upper limit=');
x=linspace(a,b,N);
h=(b-a)/(N-1);
for i=1:N-1;
T=T+h*(((f(x(i)))+(f(x(i+1))))/2);
end
plot(a,b)
am i doing something wrong
1 comentario
Oleg Komarov
el 2 de Ag. de 2012
Editada: Oleg Komarov
el 2 de Ag. de 2012
You can aslo safely drop the too many ()
h*(f(x(i))+f(x(i+1)))/2
Respuesta aceptada
Más respuestas (1)
libin danial
el 2 de Ag. de 2012
0 votos
Categorías
Más información sobre App Building en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!