CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Meshing & Mesh Conversion (https://www.cfd-online.com/Forums/openfoam-meshing/)
-   -   [Gmsh] Translating a Bisection Method writtern in Matlab to Gmsh! (https://www.cfd-online.com/Forums/openfoam-meshing/190909-translating-bisection-method-writtern-matlab-gmsh.html)

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,


All times are GMT -4. The time now is 23:49.