CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

Translating a Bisection Method writtern in Matlab to Gmsh!

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 26, 2017, 17:35
Talking Translating a Bisection Method writtern in Matlab to Gmsh!
  #1
Member
 
OpenFoam
Join Date: Jun 2016
Posts: 82
Rep Power: 9
CFD-Lover is on a distinguished road
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, so I implemented it in Matlab using for 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;
for ii=1:ceil(log2(1/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,
CFD-Lover is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
SIMPLE method with matlab houkensjtu Main CFD Forum 9 August 15, 2013 07:28
[Gmsh] discretizer - gmshToFoam Andyjoe OpenFOAM Meshing & Mesh Conversion 13 March 14, 2012 04:35
Code for most powerfull FDV Method D.S.Nasan Main CFD Forum 6 September 4, 2008 02:08
matlab code galerkin method? Mink Main CFD Forum 3 May 23, 2007 06:03
Gudunow method in matlab student Main CFD Forum 2 November 6, 2004 08:32


All times are GMT -4. The time now is 06:22.