Solving Blasius Equation (problem) using shooting technique

 This is a simple code (reduced number of lines and well explained) to implement Blasius Boundary Layer solution through Shooting technique. Here 'ODE45' and 'Fsolve' have been used in place of RK-4 and Newton Raphson, to reduce the number of lines as well as complexity.

 

 ** You have to edit the final graph to represent it properly using :Edit> Figure Properties

 MATLAB CODE:

clc;clear all;close all;
x=0.5; %% initialise a random variable with random value
format Long;
options = optimset('Display','iter');
x1= fsolve(@solver,x);  % using fsolve for convergence monitoring.
                        %This is an inbuild function from matlab others can use seperate
                        % Newton Raphson method coded in user defined format
% solver is an user defined function which will perform 'RK4' using 'ODE45' and return the desired value to 'fsolve'
function F=solver(x)
%performin intrigration using 'ODE45' inbuild func from matlab
t=0:0.1:10;
options=odeset('RelTol',1e-8,'AbsTol',[1e-8,1e-8,1e-8]);
[t,u]=ode45(@equation,t,[0 0 x], options);
for i=1:length(t)
fprintf('%f  %f   %f   %f\n',t(i),u(i,1),u(i,2),u(i,3))  %Printing variables
end
s=length(t);
F=u(s,2)-1; % returning desired value using proper boundary conditions/terminal conditions
plot(t, u(:,2),t, u(:,1),t, u(:,3)) %Ploting solved variables
end

%% defining a new function "equation" which will hold all necessary equations(blasius)
function dy=equation(t,y)
dy=zeros(3,1);
y(1);                   %write converted first order equations always
dy(1)=y(2);             %3nd order ODE converted to 3 first order equations
dy(2)=y(3);
dy(3)= -1/2*(y(3)*y(1));
end 

 

-----------------------------------------------------------

Output: 

/*................................*/

0.000000  0.000000   0.000000   0.332057
0.100000  0.001660   0.033206   0.332048
0.200000  0.006641   0.066408   0.331984
0.300000  0.014941   0.099599   0.331809
0.400000  0.026560   0.132764   0.331470
0.500000  0.041493   0.165885   0.330911
0.600000  0.059735   0.198937   0.330079
0.700000  0.081277   0.231890   0.328922
0.800000  0.106108   0.264709   0.327389
0.900000  0.134213   0.297354   0.325433
1.000000  0.165572   0.329780   0.323007
1.100000  0.200160   0.361938   0.320072
1.200000  0.237949   0.393776   0.316589
1.300000  0.278903   0.425237   0.312529
1.400000  0.322982   0.456262   0.307865
1.500000  0.370139   0.486789   0.302581
1.600000  0.420321   0.516757   0.296663
1.700000  0.473469   0.546101   0.290112
1.800000  0.529518   0.574758   0.282931
1.900000  0.588396   0.602667   0.275136
2.000000  0.650024   0.629766   0.266752
2.100000  0.714320   0.655998   0.257809
2.200000  0.781193   0.681310   0.248351
2.300000  0.850550   0.705653   0.238426
2.400000  0.922290   0.728982   0.228092
2.500000  0.996311   0.751260   0.217412
2.600000  1.072506   0.772455   0.206455
2.700000  1.150765   0.792544   0.195294
2.800000  1.230977   0.811510   0.184007
2.900000  1.313029   0.829344   0.172669
3.000000  1.396808   0.846044   0.161360
3.100000  1.482201   0.861619   0.150155
3.200000  1.569095   0.876081   0.139128
3.300000  1.657381   0.889453   0.128347
3.400000  1.746950   0.901761   0.117876
3.500000  1.837699   0.913040   0.107773
3.600000  1.929525   0.923330   0.098086
3.700000  2.022333   0.932673   0.088859
3.800000  2.116030   0.941118   0.080126
3.900000  2.210528   0.948715   0.071912
4.000000  2.305746   0.955518   0.064234
4.100000  2.401607   0.961581   0.057103
4.200000  2.498040   0.966957   0.050520
4.300000  2.594978   0.971703   0.044480
4.400000  2.692361   0.975871   0.038973
4.500000  2.790134   0.979514   0.033981
4.600000  2.888248   0.982683   0.029484
4.700000  2.986657   0.985427   0.025456
4.800000  3.085321   0.987790   0.021871
4.900000  3.184203   0.989815   0.018698
5.000000  3.283274   0.991542   0.015907
5.100000  3.382503   0.993008   0.013465
5.200000  3.481868   0.994246   0.011342
5.300000  3.581346   0.995286   0.009506
5.400000  3.680919   0.996155   0.007928
5.500000  3.780572   0.996879   0.006579
5.600000  3.880291   0.997478   0.005432
5.700000  3.980064   0.997971   0.004463
5.800000  4.079882   0.998375   0.003648
5.900000  4.179737   0.998705   0.002968
6.000000  4.279621   0.998973   0.002402
6.100000  4.379529   0.999189   0.001934
6.200000  4.479457   0.999363   0.001550
6.300000  4.579401   0.999501   0.001236
6.400000  4.679357   0.999612   0.000981
6.500000  4.779322   0.999699   0.000774
6.600000  4.879296   0.999768   0.000608
6.700000  4.979275   0.999822   0.000475
6.800000  5.079260   0.999864   0.000370
6.900000  5.179248   0.999896   0.000286
7.000000  5.279239   0.999922   0.000220
7.100000  5.379232   0.999941   0.000169
7.200000  5.479227   0.999956   0.000129
7.300000  5.579223   0.999967   0.000098
7.400000  5.679220   0.999975   0.000074
7.500000  5.779218   0.999982   0.000055
7.600000  5.879216   0.999987   0.000041
7.700000  5.979215   0.999990   0.000031
7.800000  6.079214   0.999993   0.000023
7.900000  6.179214   0.999995   0.000017
8.000000  6.279213   0.999996   0.000012
8.100000  6.379213   0.999997   0.000009
8.200000  6.479213   0.999998   0.000006
8.300000  6.579213   0.999999   0.000005
8.400000  6.679213   0.999999   0.000003
8.500000  6.779213   0.999999   0.000002
8.600000  6.879212   1.000000   0.000002
8.700000  6.979212   1.000000   0.000001
8.800000  7.079212   1.000000   0.000001
8.900000  7.179212   1.000000   0.000001
9.000000  7.279212   1.000000   0.000000
9.100000  7.379212   1.000000   0.000000
9.200000  7.479212   1.000000   0.000000
9.300000  7.579212   1.000000   0.000000
9.400000  7.679212   1.000000   0.000000
9.500000  7.779212   1.000000   0.000000
9.600000  7.879212   1.000000   0.000000
9.700000  7.979212   1.000000   0.000000
9.800000  8.079212   1.000000   0.000000
9.900000  8.179212   1.000000   0.000000
10.000000  8.279212   1.000000   0.000000
0.000000  0.000000   0.000000   0.332057
0.100000  0.001660   0.033206   0.332048
0.200000  0.006641   0.066408   0.331984
0.300000  0.014941   0.099599   0.331809
0.400000  0.026560   0.132764   0.331470
0.500000  0.041493   0.165885   0.330911
0.600000  0.059735   0.198937   0.330079
0.700000  0.081277   0.231890   0.328922
0.800000  0.106108   0.264709   0.327389
0.900000  0.134213   0.297354   0.325433
1.000000  0.165572   0.329780   0.323007
1.100000  0.200160   0.361938   0.320072
1.200000  0.237949   0.393776   0.316589
1.300000  0.278903   0.425237   0.312529
1.400000  0.322982   0.456262   0.307865
1.500000  0.370139   0.486789   0.302581
1.600000  0.420321   0.516757   0.296663
1.700000  0.473469   0.546101   0.290112
1.800000  0.529518   0.574758   0.282931
1.900000  0.588396   0.602667   0.275136
2.000000  0.650024   0.629766   0.266752
2.100000  0.714320   0.655998   0.257809
2.200000  0.781193   0.681310   0.248351
2.300000  0.850550   0.705653   0.238426
2.400000  0.922290   0.728982   0.228092
2.500000  0.996311   0.751260   0.217412
2.600000  1.072506   0.772455   0.206455
2.700000  1.150765   0.792544   0.195294
2.800000  1.230977   0.811510   0.184007
2.900000  1.313029   0.829344   0.172669
3.000000  1.396808   0.846044   0.161360
3.100000  1.482201   0.861619   0.150155
3.200000  1.569095   0.876081   0.139128
3.300000  1.657381   0.889453   0.128347
3.400000  1.746950   0.901761   0.117876
3.500000  1.837699   0.913040   0.107773
3.600000  1.929525   0.923330   0.098086
3.700000  2.022333   0.932673   0.088859
3.800000  2.116030   0.941118   0.080126
3.900000  2.210528   0.948715   0.071912
4.000000  2.305747   0.955518   0.064234
4.100000  2.401607   0.961581   0.057103
4.200000  2.498040   0.966957   0.050520
4.300000  2.594978   0.971703   0.044480
4.400000  2.692361   0.975871   0.038973
4.500000  2.790134   0.979514   0.033981
4.600000  2.888248   0.982684   0.029484
4.700000  2.986657   0.985427   0.025456
4.800000  3.085321   0.987790   0.021871
4.900000  3.184204   0.989815   0.018698
5.000000  3.283274   0.991542   0.015907
5.100000  3.382503   0.993008   0.013465
5.200000  3.481868   0.994246   0.011342
5.300000  3.581346   0.995286   0.009506
5.400000  3.680919   0.996155   0.007928
5.500000  3.780572   0.996879   0.006579
5.600000  3.880291   0.997478   0.005432
5.700000  3.980064   0.997971   0.004463
5.800000  4.079882   0.998376   0.003648
5.900000  4.179737   0.998705   0.002968
6.000000  4.279621   0.998973   0.002402
6.100000  4.379530   0.999189   0.001934
6.200000  4.479457   0.999363   0.001550
6.300000  4.579401   0.999501   0.001236
6.400000  4.679357   0.999612   0.000981
6.500000  4.779322   0.999699   0.000774
6.600000  4.879296   0.999768   0.000608
6.700000  4.979276   0.999822   0.000475
6.800000  5.079260   0.999864   0.000370
6.900000  5.179248   0.999896   0.000286
7.000000  5.279239   0.999922   0.000220
7.100000  5.379232   0.999941   0.000169
7.200000  5.479227   0.999956   0.000129
7.300000  5.579223   0.999967   0.000098
7.400000  5.679220   0.999975   0.000074
7.500000  5.779218   0.999982   0.000055
7.600000  5.879217   0.999987   0.000041
7.700000  5.979216   0.999990   0.000031
7.800000  6.079215   0.999993   0.000023
7.900000  6.179214   0.999995   0.000017
8.000000  6.279214   0.999996   0.000012
8.100000  6.379213   0.999997   0.000009
8.200000  6.479213   0.999998   0.000006
8.300000  6.579213   0.999999   0.000005
8.400000  6.679213   0.999999   0.000003
8.500000  6.779213   0.999999   0.000002
8.600000  6.879213   1.000000   0.000002
8.700000  6.979213   1.000000   0.000001
8.800000  7.079213   1.000000   0.000001
8.900000  7.179213   1.000000   0.000001
9.000000  7.279213   1.000000   0.000000
9.100000  7.379213   1.000000   0.000000
9.200000  7.479213   1.000000   0.000000
9.300000  7.579213   1.000000   0.000000
9.400000  7.679213   1.000000   0.000000
9.500000  7.779213   1.000000   0.000000
9.600000  7.879213   1.000000   0.000000
9.700000  7.979213   1.000000   0.000000
9.800000  8.079213   1.000000   0.000000
9.900000  8.179213   1.000000   0.000000
10.000000  8.279213   1.000000   0.000000

Equation solved.

fsolve completed because the vector of function values is near zero
as measured by the default value of the function tolerance, and
the problem appears regular as measured by the gradient.

<stopping criteria details>

 

------------

 



 

 

Comments

Post a Comment