MATLAB Answers

trapezoidal numerical integration within a function

1 ビュー (過去 30 日間)
Rhea Gorringe
Rhea Gorringe 2020 年 5 月 15 日
回答済み: Nikhil Sonavane 2020 年 5 月 19 日
Hello :)
I need to perform a trapezoidal intergration however i am unsure how to do this inside a fuction as i have only every done it with out. any help is very much apriacted.

  3 件のコメント

Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
There is no difference in calling a function inside or outside a function. Have you written your own code for trapezoidal integration, or are you using trapz()?
Rhea Gorringe
Rhea Gorringe 2020 年 5 月 15 日
trapz() i think. this is my first time trying to use matlab on my own i have this so far (i know it wrong)
function tarea = trapezint(inarray,llim,ulim)
inarray=0;
llim=1;
ulim=100;
h=(llim-inarray)/ulim;
sum=0;
f=@(x) x.*sin(x);
for i=1:1:n-1
sum= sum + f(inarray+i*ulim);
qt=sum((h*f((x(1:ulim)+x(2:ulim+1)))/2)
Ameer Hamza
Ameer Hamza 2020 年 5 月 15 日
Are you trying to integrate x*sin(x) from 1 to 100? What is the role of 'inarray' here?

サインインしてコメントする。

回答 (1 件)

Nikhil Sonavane
Nikhil Sonavane 2020 年 5 月 19 日
I would suggest you go through the documentation of trapz function as that would help you trapezoidal numerical integration efficiently.

  0 件のコメント

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by