Trying to Plot a Function

Working on a Nuclear Engineering problem, we have to plot the relationship between Keff and the diameter of a cylinder. Here is where I'm stuck:
>> %%Keff%%
nu=2.65;
Density=19.1;
MW=235;
N=(Density/MW)*6.022*10^23;
MicF=1.235*10^-24;
MicA=1.335*10^-24;
MicS=4.566*10^-24;
MacF=MicF*N;
MacA=MicA*N;
MacS=MicS*N;
A=235;
MuBar=2/(3*A);
D=1/(3*MacS*(1-MuBar));
H=30;
Diam=(1:180);
Keff=(nu*MacF)/(MacA+(D*((pi/H)^2+((2*2.4050)/Diam)^2)));
plot(Keff,Diam);
xlabel("Keff");
ylabel("Diameter");
title("Relationship Between Keff and Diameter");
Error using /
Matrix dimensions must agree.
Any ideas on how to fix this code. I just want a plot of the relationship.

5 件のコメント

Arif Hoq
Arif Hoq 2022 年 1 月 31 日
編集済み: Arif Hoq 2022 年 1 月 31 日
Try with this
clear;
clc;
nu=2.65;
Density=19.1;
MW=235;
N=(Density/MW)*6.022*10^23;
MicF=1.235*10^-24;
MicA=1.335*10^-24;
MicS=4.566*10^-24;
MacF=MicF*N;
MacA=MicA*N;
MacS=MicS*N;
A=235;
MuBar=2/(3*A);
D=1/(3*MacS*(1-MuBar));
H=30;
Diam=(1:180);
Keff=(nu*MacF)./(MacA+(D*((pi/H)^2+((2*2.4050)./Diam).^2))); % element by element
plot(Keff,Diam);
xlabel("Keff");
ylabel("Diameter");
title("Relationship Between Keff and Diameter");
I think you have to create your matrix element by element, like ./ and .^
For example
A = [1 1 0 0];
B = [1; 2; 3; 4];
C = A*B
C = 3
D= A.*B % element by element
D = 4×4
1 1 0 0 2 2 0 0 3 3 0 0 4 4 0 0
Kevin Smith
Kevin Smith 2022 年 1 月 31 日
Arif: you are a steely-eyed missle man! Thank you!
Arif Hoq
Arif Hoq 2022 年 1 月 31 日
@Kevin Smith Thank you very much for your compliment. If you find your answer, then please consider marking it as accepted answer. That will make it easier for others with similar issues to find an answer.
KSSV
KSSV 2022 年 1 月 31 日
@Arif Hoq you have commented the code. It cannot be accepted unless you copy it in answer section.
Arif Hoq
Arif Hoq 2022 年 1 月 31 日
@KSSV thanks a lot. I was not such aware of it.

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

回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 1 月 31 日

0 投票

Try with this:
clear;
clc;
nu=2.65;
Density=19.1;
MW=235;
N=(Density/MW)*6.022*10^23;
MicF=1.235*10^-24;
MicA=1.335*10^-24;
MicS=4.566*10^-24;
MacF=MicF*N;
MacA=MicA*N;
MacS=MicS*N;
A=235;
MuBar=2/(3*A);
D=1/(3*MacS*(1-MuBar));
H=30;
Diam=(1:180);
Keff=(nu*MacF)./(MacA+(D*((pi/H)^2+((2*2.4050)./Diam).^2))); % element by element
plot(Keff,Diam);
xlabel("Keff");
ylabel("Diameter");
title("Relationship Between Keff and Diameter");
I think you have to create your matrix element by element, like ./ and .^
For example
A = [1 1 0 0];
B = [1; 2; 3; 4];
C = A*B
C = 3
D= A.*B % element by element
D = 4×4
1 1 0 0 2 2 0 0 3 3 0 0 4 4 0 0

カテゴリ

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

質問済み:

2022 年 1 月 31 日

編集済み:

2022 年 1 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by