MATLAB Answers

Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Need help with 1/ matrix in problem

1 ビュー (過去 30 日間)
Richard Morrill
Richard Morrill 2019 年 9 月 18 日
終了済み: MATLAB Answer Bot 2021 年 8 月 20 日 18:34
I have an equation that must be solved that keeps throwing the error "Error using /
Matrix dimensions must agree."
The code I have is
% Finding Delt H
syms dh
eqn2=log(p_rng)== (dh/R)*(1/t_rng)
for i=1:300
D_h(i,:)=double(vpa(solve(eqn2(i),dh)));
end
It seems as though 1/t_rng is what causes the error. When changed to just t_rng the error no longer occures
  1 件のコメント
madhan ravi
madhan ravi 2019 年 9 月 18 日
size(p_rng)
size(t_rng) % ?
Do you realise there is only one eqn2 but then you run a loop through it ? Probably you meant to run a loop through variable elements of t_rng and p_rng ? Beware D_h isn’t preallocated.

回答 (1 件)

Kevin Phung
Kevin Phung 2019 年 9 月 18 日
編集済み: Kevin Phung 2019 年 9 月 18 日
you're going to need the dot operator (.) for element-wise operations.
Probably something like this:
syms dh
eqn2=log(p_rng)== (dh./R).*(1./t_rng)
for i=1:300
D_h(i,:)=double(vpa(solve(eqn2(i),dh)));
end
  1 件のコメント
Stephen
Stephen 2019 年 9 月 19 日
Read this to know the differences between array and matrix operations:

Community Treasure Hunt

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

Start Hunting!

Translated by