CFD-Lover |
July 25, 2017 22:29 |
Translating a Bisection Method writtern in Matlab to Gmsh!
Hi,
I have written a Bisection method code in Matlab, and I really want to write in Gmsh if that possible. I have read that Gmsh doesn't support the so-called while loop. Is there any why to implemented in Gmsh. The code is below;
Code:
clear all;clc;close all
% -------------------------------------------------------------------------
format long
n = 30;
L = 2;
Start = 0.012;
i = 0:1:(n-1-1);
%--------------------------------------------------------------------------
Function = @(r) L-sum(Start.*r.^i); % anaymos function
low = 0;
high = pi/2;
tol = 0.00001;
mid = (low+high)/2;
while abs(Function(mid))>tol
if Function(mid)*Function(high) < 0 % Solution is within upper half
low = mid;
else % Solution is within lower half
high = mid;
end
fprintf('Solution lies within [%6.4f, %6.4f]; \n',[low high]);
mid = (low+high)/2;
end
display(mid)
Thank you so much for your time,
|