Error Matrix dimensions must agree

1 回表示 (過去 30 日間)
jack carter
jack carter 2017 年 7 月 5 日
コメント済み: jack carter 2017 年 7 月 6 日
I am getting "Matrix dimensions must agree" error while running the following codings in MatLab. From the first two equations I am getting error because of exp(f.*phi) part. If I remove this part, the code works fine. But I need to add this in both equations. In the last equation I am getting error due to the factor_c part. Could someone help me correcting the mistakes? Thanks
function myfunction
n=0;Ef=40*10^6;df=0.014;rou=3*10^6;S=0:600;f=0.5;phi=0:0.01:pi/2;Le=2;Vf=0.02;
P_friction=(pi/2)*sqrt((1+n)*Ef*df^3*rou*S).*exp(f.*phi);
Pslip=pi*rou*Le*df*(1-S/Le)*exp(f.phi);
factor_a=(4*Vf/(pi*df^2));
factor_b=Pslip.*P_friction;
factor_c=p_phi*p_z;
sigmab=factor_a.*factor_b.*factor_c;
end

採用された回答

Star Strider
Star Strider 2017 年 7 月 5 日
First, you need an operator here, I assume multiplication:
Pslip=pi*rou*Le*df*(1-S/Le)*exp(f.*phi);
↑ ← INSERT ‘*’ HERE
What are ‘p_phi’ and ‘p_z’ here:
factor_c=p_phi*p_z;
I do not see where you have defined them, and your function does not have any arguments. A function file will not pick up variables from your workspace as an anonymous function would.
  4 件のコメント
jack carter
jack carter 2017 年 7 月 5 日
It is working fine with your codings. May I ask in case if we modify the value of p(z) while keeping the rest of the codings same,
z=0:Lf./(2*cos(phi));
p(z)=2*z/Lf;
Star Strider
Star Strider 2017 年 7 月 5 日
If you want all the vectors to be the same lengths, you will have to define ‘z’ as:
z = bsxfun(@rdivide, [0:Lf]', 2*cos(phi));
p = 2*z/Lf;
This creates a (3x100) matrix for ‘p’.
You cannot use 0 as a subscript. In MATLAB, indexing begins with 1.

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

その他の回答 (1 件)

KSSV
KSSV 2017 年 7 月 5 日
Your S and phi should be arrays with equal dimensions. In your code they are not same. You need to proceed like below.
N = 100 ; % can be changed
n=0;
Ef=40*10^6;
df=0.014;
rou=3*10^6;
S = linspace(0,600,N) ;% S=0:600;
f=0.5;
phi = linspace(0,pi/2,N) ;% phi=0:0.01:pi/2;
Le=2;
Vf=0.02;
P_friction=(pi/2)*sqrt((1+n)*Ef*df^3*rou*S).*exp(f*phi);
Pslip=pi*rou*Le*df*(1-S/Le).*exp(f*phi);
  1 件のコメント
jack carter
jack carter 2017 年 7 月 6 日
Thank you for your reply

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by