How to convert pseudo code into MAT LAB

12 ビュー (過去 30 日間)
Alex Benny
Alex Benny 2019 年 11 月 20 日
コメント済み: Steven Lord 2023 年 5 月 24 日
single-segment
function trap(h,f0,f1)
Trap = h* (f0 + f1)/2
end trap
multiple segment
funiton trapm(h,n,f)
sum = f0
dofor 1 = 1, n-1
sum = sum + 2 *f;
end do
sum = sum +fn
trapm = h * sum/2
end trapm
  1 件のコメント
Rik
Rik 2019 年 11 月 20 日
Have a read here and here. It will greatly improve your chances of getting an answer.

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

回答 (2 件)

Puru Kathuria
Puru Kathuria 2020 年 3 月 2 日
Hi,
I understand that you want to convert the mentioned above pseudocode into MATLAB. Below is the mentioned implementation of your pseudocode in MATLAB.
% single-segment
function trapSingle = trap(h,f0,f1)
trapSingle = h* (f0 + f1)/2;
end
% multiple segment
function trapMultiple = trapm(h,n,f)
sum = f(1);
for i = 2: n-1
sum = sum + (2 *f(i));
end
sum = sum + f(n) ;
trapMultiple = h * (sum/2);
end
  1 件のコメント
Fatma HM
Fatma HM 2021 年 6 月 6 日
Hello Mr. Puru Kathuria I have a matlab code I need to convert it to pseudo code plz can you help me ?

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


Rahma Abbas
Rahma Abbas 2023 年 5 月 24 日
編集済み: Rahma Abbas 2023 年 5 月 24 日
How to convert this pseudocode to a MATLAB code?
ALGORITHM ETD(E, T, A, L, D)
1 Find the tree E2 that is the same as E except that
pointers from the parents to the children are
reversed.
2 Create arrays D1 and D2, and
initialize i = path_length(L);
3 current_node = L;
4 while (current_node ≠ R)
5 D1[i] = T[current_node];
6 mutation_number =
Hamming(A(current_node), A(R));
7 D2[i] = mutation_number;
8 current_node = current_node.next(in E2);
9 i = i-1;
10 end
11 D1[i] = T(R);
12 D2[i] = 0;
13 D = Cubic_Spline(D1,D2);
14 Return D;
  1 件のコメント
Steven Lord
Steven Lord 2023 年 5 月 24 日
Can you show us the code you've written so far to try to implement this algorithm and ask a specific question about where you're having difficulty? If you do we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by