The integral with the Trapezoidal method

The C code, which finds the following integral with the Trapezoidal method, is given below. I want to solve this question below in Matlab but i didn't do it. This is simple question but i can't do it. If someone will help me, i will be very happy.
My tried Matlab code:

4 件のコメント

Mathieu NOE
Mathieu NOE 2021 年 1 月 20 日
hello
you should share your code , but I already can tell where the issues are :
  • line 8 : the if statement is not correct , it's not about x , it's about checking that i = 0 or n (start and final integration steps)
  • line 9 : should be : sum =sum+f(x)
  • line 11 : should be : sum =sum+2*f(x)
  • line 13 : to be removed
still what you have to implement in a subfunction to evaluate f(x) from the current x value (from line 7)
Rooter Boy
Rooter Boy 2021 年 1 月 21 日
Sir, I don't know use Matlab well. If you will help me, i will be very happy, so i need a code block.
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 1 月 21 日
If you have just started using matlab it is typically a good idea to look at the matlab onramp videos, demos and presentations etc. That way you will get up to speed on everything matlab-related faster, and then you can proceed faster with the programming-tasks and it will be clearer what part of your problems are matlab-related and what parts are related to algorithms or numerical issues.
Also welcome to matlab-central!
Mathieu NOE
Mathieu NOE 2021 年 1 月 21 日
let me see that you have started to work out your code and i'll be happy to give you a hand ...

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2021 年 1 月 20 日

コメント済み:

2021 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by