How do i make this into code

Hey all i am wondering how i make the below picture into actual code. Any help would be greatly appreciated.

回答 (1 件)

Image Analyst
Image Analyst 2021 年 8 月 19 日

0 投票

Did you try using sum(), like
% Create some sample data
N = 4
r = randi(9, N, 1)
u = randi(9, N, 5)
% Now do the equations
ru = r(2:N-1) .* u(2:N-1, :)
usum = sum(ru)
delta_r = 1; % Whatever it is.
uintj = delta_r * ( (1/2) * r(1) * u(1, :) + usum + (1/2) * r(N) * u(N, :))

6 件のコメント

Dylan Bull
Dylan Bull 2021 年 8 月 19 日
wouldnt that sum everything including the first and last vlaues rather than just the middle vlaues? or would it make the values of unitj which im thinking would still be a 1x65 array no? because then i have to take that array and add it all together again to get one final number. i could be very wrong on this but i thought that was the right answer.
Dylan Bull
Dylan Bull 2021 年 8 月 19 日
編集済み: Dylan Bull 2021 年 8 月 19 日
to calirfy i have to do this twice as next ill have to do this.
Image Analyst
Image Analyst 2021 年 8 月 19 日
No. Note that ru is the multiplication of only the middle values, between indexes 2 and N-1, not all indexes between 1 and N.
Dylan Bull
Dylan Bull 2021 年 8 月 19 日
so in order to do all of it i would just repeat and do the exact same thing for the nex set?
Dylan Bull
Dylan Bull 2021 年 8 月 19 日
also when attmepting to use this i get the follow error.
Arrays have incompatible sizes for this operation.
Error in project2 (line 180)
ru = r(2:N-1) .* u(2:N-1, :)
Image Analyst
Image Analyst 2021 年 8 月 19 日
Well I don't know what the first 179 lines of your script do but evidently r is not a column vector.

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

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 8 月 18 日

コメント済み:

2021 年 8 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by