iteration with biscetion method

3 visualizzazioni (ultimi 30 giorni)
Claus Madsen
Claus Madsen il 12 Mar 2013
Hello i need som help with program this code. I have the following parameters in a matrix[1566,1] R, I, Q_min, Q_max, A and d. And i want to solv the eq with the biscetion methode. i want the result to come out in a matriv?
%%%%%%%%%%%%%%%%%%%%%%%%%%Parameter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data=xlsread('ledning.xls');
Q_min=data(:,2);
R=data(:,5)/4; % Hydraulisk radius for fuldløbende ledning
I=data(:,4); %I=I_0 dvs. slope
A=(data(:,5)/2).^2*3.14;
M=75;
d=data(:,5);
for i=1:length(data)
Q_max(i,1)=abs(A(i,1)*M*(I(i,1)/100)^(1/2)*R(i,1)^(2/3));
end
for i=1:length(data)
p(i,1)=Q_min(i,1)/Q_max(i,1);
end
%%%%%%%%%%%%%%%%%%%%%%%%Ligning der skal løses %%%%%%%%%%%%%%%%%%%%%%%%%%%
%Ligningen løses via biscetion metoden
f=@(y) (0.46-0.5*cos(3.14*(y/d))+0.004*cos(2*3.14*(y/d)))-(p); %delfyldningsformel
format long
%%%%%%%%%%%%%%%%%%%%%%%%Betingelser til biscetion %%%%%%%%%%%%%%%%%%%%%%%%
eps_abs = 1e-5;
eps_step = 1e-5; %%%%abs og step angiver hvor tæt resultaterne skal være på hinanden
a = 0; % Initial Guess to your function such that f(a)>0.
b = 0.2; % Initial Guess to your function such that f(b)<0.
%%%%%%%%%%%%%%%%%%%%%%%%Påbegynd loop %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
while (b - a >= eps_step || ( abs( f(a) ) >= eps_abs && abs( f(b) ) >= eps_abs ) )
c = (a + b)/2;
if ( f(c) == 0 )
break;
elseif ( f(a)*f(c) < 0 )
b = c;
else
a = c;
end
end
  1 Commento
Jan
Jan il 12 Mar 2013
What does the posted code do in opposite to your demands?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Simulink in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by