Help Using Newton Rhapson Method for Colebrook equation

11 ビュー (過去 30 日間)
Mary Fasulo
Mary Fasulo 2020 年 2 月 18 日
コメント済み: Yagmur Atalayin 2020 年 5 月 26 日
For context, the homework assignment wants us to use the Newton Rhapson method to solve for the friction value using Colebrook's equation. I have my code below but I keep getting errors saying that in line 18 matrix dimensions must agree. I'm not exactly sure what the issue is and our professor told us to approach the problem this way. Any help would be greatly appreciated. Code is attached

採用された回答

Lemuel Carlos Ramos Arzola
Lemuel Carlos Ramos Arzola 2020 年 2 月 18 日
Hello Mary,
The problem is with the function:
diff(h(x))
This function operates with vectors and it only computes the difference. Also, to obtain the derivative you need to divide by an appropriate step size. You have two options here:
  1. Compute the exact derivative with a symbolic asistant (or by hand ...) and then add to your code in line 16.
  2. Approximate the derivative with a centered finite difference (or backward,forward).
I used here the second option,
x0 = 0.01; %Guess for initial x
x=x0;
dx = 1e-3; % Step size for the centered finite difference
for i=0:100000
y=x;
m = (h(x+dx) - h(x-dx)) / (2*dx); % centered finite difference
x = y-(h(x)/m);
if x==y
break
end
end
Best.
  5 件のコメント
Mary Fasulo
Mary Fasulo 2020 年 2 月 18 日
Thank you I highly appreciate it.
Lemuel Carlos Ramos Arzola
Lemuel Carlos Ramos Arzola 2020 年 2 月 19 日
編集済み: Lemuel Carlos Ramos Arzola 2020 年 2 月 19 日
You are welcome. I am a hydraulic engineer and in a few occasions I used that formula. But I prefer the explicit formula of Swamee-Jain.

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

その他の回答 (1 件)

Yagmur Atalayin
Yagmur Atalayin 2020 年 5 月 26 日
Can I help me please
  3 件のコメント
Yagmur Atalayin
Yagmur Atalayin 2020 年 5 月 26 日

How can I write marry's question at Matlab programme ,using newton Raphson and colebrook ? Please help me! Pleaseeeeee :( if I don't solve this problem ,I can failure at my lesson

Yagmur Atalayin
Yagmur Atalayin 2020 年 5 月 26 日
How can I solve marry's problem at matlab using newton Raphson and colebrook , help me please if I don't solve this problem I can failure in my lesson

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

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by