Writing expression for summation on mathlab

1 回表示 (過去 30 日間)
Prince Igweze
Prince Igweze 2019 年 12 月 1 日
回答済み: Mack Duffy 2019 年 12 月 1 日
how can i write this on mathlab
  1 件のコメント
Ajay Kumar
Ajay Kumar 2019 年 12 月 1 日
編集済み: Ajay Kumar 2019 年 12 月 1 日
Have you tried it before asking the question? If not please do try first.
You can use for loops for iterating i.e. j from 1 to N and to iterate other variables.
and I see nothing except that in the equation, you can use basic built-in functions in matlab to perform squareroot(sqrt) operations.
for squaring you can always use ^2 or .^2 for element wise squaring.
doc for
doc sqrt

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

回答 (1 件)

Mack Duffy
Mack Duffy 2019 年 12 月 1 日
This is the summation for the midpoint numerical integration method. This is an example of how to turn a summation into matlab code. Hope this helps somewhat.
function [Y] = midpoint_integration(A,B,N,S)
D = (A-B)/N;
W = str2func(['@(X)' S]);
Y=0;
for i = 0:(N-1)
Y = Y + W((B+D/2)+i*D);
end
Y = Y*D;
U = error_midpoint(A,B,N,S);
answer_output = (' \n \n The area under the curve is %4.2f and the error bounds is %4.2f \n');
fprintf(answer_output,Y, U);
end
%A is the upper bound
%B is the lower bound
%N is the number of of sub intervals
%S is the function you want to integrate

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by