How do i fix this error?

27 ビュー (過去 30 日間)
Daniel
Daniel 2025 年 9 月 24 日 21:23
編集済み: Torsten 2025 年 9 月 28 日 23:56

回答 (1 件)

dpb
dpb 2025 年 9 月 24 日 21:58
編集済み: dpb 2025 年 9 月 26 日 12:42
Paste the code as text and the complete error message; can't do anything with an image.
The statement
f=zeros(num_pipes,1);
creates a vector of three elements so when you write
for i=1:num_pipes
...
f(i)=32*f*pipe_length(i)*Q(i)^2 ...
then the RHS is going to also be a 3-vector of zeros that you're trying to store into one location. Can't do that.
One presumes the second, unsubscripted f is supposed to be a friction factor based on some other correlation. Fix that to be some other scalar variable.
  3 件のコメント
Daniel
Daniel 2025 年 9 月 28 日 18:55
Here is the full code with the error message.
Torsten
Torsten 2025 年 9 月 28 日 19:09
編集済み: Torsten 2025 年 9 月 28 日 23:56
% Calculate Darcy-Weisbach friction factor using the given equation
f(i) = (32 * f * pipe_length(i) * Q(i)^2) / (pi * gc * pipe_diameter(i)^5);
This f (bold)
f(i) = (32 * f * pipe_length(i) * Q(i)^2) / (pi * gc * pipe_diameter(i)^5);
is a vector while this f(i) (bold)
f(i) = (32 * f * pipe_length(i) * Q(i)^2) / (pi * gc * pipe_diameter(i)^5);
is a scalar.
So you try to assign a vector
(32 * f * pipe_length(i) * Q(i)^2) / (pi * gc * pipe_diameter(i)^5);
to a scalar
f(i)
- consequently the error message.
@dpb suspected that f is a friction factor you forgot to specify in your code - thus that f is different from f(i). We don't know.
Shouldn't the headloss be prescribed externally if you want to compute volumetric flowrates ? I get the impression that both quantities are treated as unknowns in your code.

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

カテゴリ

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

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by