How to display a table and a graph for this code?

1 vue (au cours des 30 derniers jours)
Adrian Lira Saucedo
Adrian Lira Saucedo le 28 Jan 2020
Commenté : Walter Roberson le 28 Jan 2020
I want to show al the n iterations of this code in order to be shown in a table. Also I'd like to graph the result but I don't know how.
function I=trap(a,b,n,f)
function I=trap(a,b,n,f)
h = (b-a)/n ;
s = feval(f,a) ;
for i=1:n-1
x(i) = a + i*h ;
s = s+2 * feval (f,x(i)) ;
end
s = s + feval(f,b) ;
I = s*h/2 ;
% fprintf('\nanswer is %11.6f=\n',I)
end
  1 commentaire
Walter Roberson
Walter Roberson le 28 Jan 2020
T = array2table(x.', 'VariableNames', {'x'});
plot(x)

Connectez-vous pour commenter.

Réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by