clear;
clc;
close all;
radian_to_deg = 180/pi;
degree_to_radian = pi/180;
prompt = "Enter a Mach Number ranging from 1.5 to 4: ";
Me = input(prompt);
prompt_1 = "Enter the number of divisions: ";
n_div = input(prompt_1);
prompt_2 = "Enter the throat radius: ";
TR = input(prompt_2);
g = 1.4;
mach_angle= [];
theta = [];
theta_a = [];
y=[];
x=[];
v=[];
v_a=[];
ma_f = @(x) asind(1/x) ;
A = sqrt((g+1)/(g-1));
B = (g-1)/(g+1);
pm_f = @(x) (A*atand(sqrt(B*(x^2-1))) - atand(sqrt(x^2-1)));
theta_max = pm_f(Me)/2;
theta_i = sign(theta_max)*(abs(theta_max) - floor(abs(theta_max)));
for i = 1:n_div
theta_a(i,1) = theta_i ;
theta_i = theta_i + 3.0;
end
v_a = theta_a;
ya=1;
xa=0;
v_a(1,1) = theta_a(1,1);
y(1,1) = 0;
Km_1 = theta_a(1,1) + v_a(1,1);
theta(1,1)= 0.5*(Km_1);
v(1,1) = 0.5*(Km_1);
syms x
f = @(x) (A*atand(sqrt(B*(x^2-1))) - atand(sqrt(x^2-1))-v(1,1));
f1 = matlabFunction(diff(f(x)));
change = 10;
Mguess = 1.1;
while (change>1e-6)
Mnew = Mguess - f(Mguess)/f1(Mguess);
change = abs(Mguess - Mnew);
Mguess = Mnew;
end
mach_angle(1,1) = ma_f(Mnew);
x(1,1) = (-ya/tand(theta(1,1)-mach_angle(1,1)))