1
votes

While solving one problem in the fluid mechanics topic, I came across a situation where I have to solve 4 non linear equation to get 4 unknown variable values. So, I used fsolve function in scilab to solve the equations. My code is as follows:

clc
clear

function f=F(x)
f(1)=x(1)-(0.4458*x(2)^(-2))
f(2)=x(3)-(0.26936*x(2)*(-1)) 
f(3)=(2.616*x(2))-(x(4)*x(1)^2)
f(4)=(0.316/(x(3)^(1/4)))
endfunction
function j=jacob(x)
 j(1,1)=1;j(1,2)=0.8916*x(2)^(-3);j(1,3)=0;j(1,4)=0
 j(2,1)=0;j(2,2)=0.26936*x(2)^(-2);j(2,3)=1;j(2,4)=0;
 j(3,1)=-2*x(1)*x(4);j(3,2)=2.616;j(3,3)=0;j(3,4)=-1*x(1)^2;
 j(4,1)=0;j(4,2)=0;j(4,3)=-2/x(3)/log(10);j(4,4)=(-0.5*x(4)^(-1.5))-(1/x(4)/log(10));
endfunction
x0=[1 1 2000 1];
[x,v,info]=fsolve(x0,F,jacob);
disp(x);

Error:

[x,v,info]=fsolve(x0,F,jacob); !--error 98 Variable returned by scilab argument function is incorrect. at line 17 of exec file called by :
exec('D:\Desktop files\Ajith\TBC\SCILAB code\Chapter_08\fsolve.sce', -1)

Details of the question:-

Actual question: Heated air at 1 atm and 35 degree C is to be transported in a 150m long circular plastic duct at a rate of 0.35 m3/s. If the head loss in the pipe is not to exceed 20m, determine the minimum diameter of the duct?

Book name: Fluid Mechanics: Fundamentals and Applications by Y.A.Cengel and J.M.Cimbala.

Page and question number: Page no.: 345, EXAMPLE 8-4

ISBN of the book: 0-07-247236-7

Textbook link: https://www.academia.edu/32439502/Cengel_fluid_mechanics_6_edition.PDF

In my code: x(1) is velocity, x(2) is the diameter, x(3) is the Reynolds number, x(4) is the friction factor

Expected answers: x(1)=6.24, x(2)=0.267, x(3)=100800, x(4)=0.0180.

My thoughts about the error:

  1. What is see is that if I change the power of the variable such as from 0.5 to 2 or -1.5 to 1, answer is calculated and displayed. So, the problem is somewhere around the power of the variables used.
  2. Also the initial values of the x, I saw that for some initial value there is no error and I got the output.
1

1 Answers

0
votes

After reading the description of the problem in the book, there is only one non-trivial equation (the third) all other give directly other unknowns as functions of D. Here is the code to determine the diameter:

function out=F(D)
    V = 0.35/%pi/D^2*4;
    Re = V*D/1.655e-5;
    f = 20/(150/D*V^2/2/9.81);
    out = 1/sqrt(f) + 2*log10(2.51/Re/sqrt(f));    
endfunction
D0 = 1;
[D,v,info]=fsolve(D0,F);
disp(D)