Convert this C program into a Matlab program.

ex[1]=lx/J %%first i term in ex matrix
ex[2]=mx/J %%second j term in ex matrix
ex[3]=nx/J %%third k term in ex matrix
for (i=0;i<9;i++)
for (j=0;i<27;j++)
N_matrix[i,j]=0;
end
for (i=0;i<9;i++)
N_matrix(0,i)=N[i%3]*ex[i/3];
end

4 件のコメント

Kevin Chng
Kevin Chng 2018 年 10 月 16 日
ex[1]=lx/J
%%first i term in ex matrix ex[2]=mx/J
%%second j term in ex matrix ex[3]=nx/J
%%third k term in ex matrix
for (i=0;i<9;i++)
for (j=0;i<27;j++)
N_matrix[i,j]=0;
end
for (i=0;i<9;i++)
N_matrix(0,i)=N[i%3]*ex[i/3];
end
I don't think anyone will answer this to you.
Adam
Adam 2018 年 10 月 16 日
As C code goes that is about as trivial as it comes to convert to Matlab! It's just a few minor syntax changes (though vectorisation would be better than the straight for loop conversion).
Jan
Jan 2018 年 10 月 16 日
編集済み: Jan 2018 年 10 月 16 日
@Virajan Verma: You are not a newbie in this forum. I've formatted the code for your today, but please mark the code with the mouse and press the "{} Code" button by your own in the future. Thanks.
This is not C code, because there is no "end" in C. What is N? Are you sure that you want to insert values in the first row, not column?
Guillaume
Guillaume 2018 年 10 月 16 日
N_matrix(0,i) is also not correct C syntax. The brackets should be square.
And as Jan pointed out, it should probably be:
N_matrix[i,0]

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

回答 (1 件)

Jan
Jan 2018 年 10 月 16 日

1 投票

ex = [lx; mx; nx] / J;
N = rand(3, 1); % ???
N_matrix = zeros(9, 27);
N_matrix(1, 1:9) = repmat(N, 3, 1) .* repelem(ex, 3, 1)

4 件のコメント

Virajan Verma
Virajan Verma 2018 年 10 月 18 日
編集済み: Walter Roberson 2018 年 10 月 18 日
How do i convert this??
for i=1:9
N_matrix(5,i+9)= N(rem(i,3))*ez(i/3);
N_matrix(2,i)=N(rem(i,3))*ez(i/3);
end
Virajan Verma
Virajan Verma 2018 年 10 月 18 日
編集済み: Walter Roberson 2018 年 10 月 18 日
N(1)=0.5*(epsilon3*epsilon3-epsilon3); %%epsilon=natural coordinte
N(2)=(1-epsilon3*epsilon3);
N(3)=0.5*(epsilon3*epsilon3+epsilon3);
epsilon3 has 3 values: 1, 2, 3.
Virajan Verma
Virajan Verma 2018 年 10 月 18 日
@Jan
Walter Roberson
Walter Roberson 2018 年 10 月 18 日
That code creates a row vector for N, not a column vector. Try N(1,1), N(2,1), N(3,1) as the destinations

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

カテゴリ

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

タグ

質問済み:

2018 年 10 月 16 日

コメント済み:

2018 年 10 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by