フィルターのクリア

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Can someone help me with my code? Topic: integration

1 回表示 (過去 30 日間)
LB
LB 2016 年 10 月 10 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Hi everyone!
I am going to calculate the integral of a function V(j). I have already found the values for V and j. I am going to use the following formulas to calculate the integral:
S(j) = S(j-1) + 1/2V(j-1)+1/2V(j) for j>=1
S(0) = 0 for j= 0
How can I write this in matlab? Hope someone can help me out here :)
  2 件のコメント
KSSV
KSSV 2016 年 10 月 10 日
YOu want to put that into loop?
LB
LB 2016 年 10 月 10 日
Yes! And I don't know exactly how to write it to get the correct values.

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2016 年 10 月 10 日
編集済み: Andrei Bobrov 2016 年 10 月 10 日
out = trapz(V);
or
out = sum(V) - sum(V([1,end]))/2;
or
S = cumtrapz(V);
or
S = [0,cumsum(sum([V(1:end-1);V(2:end)])/2)];
or
S = [0;cumsum(filter2([.5;.5],V(:),'valid'))];

Luca  Fenzi
Luca Fenzi 2016 年 10 月 10 日
Dear LeneB, You should truncate the sum (S(j) = S(j-1) + 1/2V(j-1)+1/2V(j) for j>=1) up to N: in this way knowing V(j) for all j you can evaluate S with the following code:
N=10000; %%Truncation order of the sum
S=zeros(1,N); % Initialisation of the vector S
% S(1)=0 corresponds to S(0)=0 for j=0
% Define V(j) for j=1:N.
for i=2:N
S(i) = S(i-1) + 1/(2*V(i-1))+1/(2*V(i))
end

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by