Borrar filtros
Borrar filtros

Mach Number Area Relation Several Inputs

3 visualizaciones (últimos 30 días)
Steven Castrillon
Steven Castrillon el 30 de Sept. de 2019
Comentada: Jim Riggs el 1 de Oct. de 2019
The following code inputs a single input (ARatio) and outputs two terms (Msub) & (Msup)
I want to be able to input several ARatio values, more specifically an array from 0.1 to 10 with an increment of 0.1
and have Msub & Msup for each of these ARatio stored in an array in order to plot ARatio and Mach number.
clear;
clc;
%% INPUTS
% Define some paramters
g = 1.4;
gm1 = g-1;
gp1 = g+1;
% Define anonymous function with two inputs (M and ARatio)
% - Will be used in the methods below
% - Pass M and ARatio as arguments to AM_EQN to get function value
% - funVal = AM_EQN(M,ARatio)
AM_EQN = @(M,ARatio) sqrt((1/M^2)*(((2+gm1*M^2)/gp1)^...
(gp1/gm1)))-ARatio;
% Solve for Msub and Msup using this area ratio (A/A*)
ARatio = 1.5;
% Error tolerance
errTol = 1e-4;
% Flags for printing iterations to screen
verboseBisection = 0;
verboseIncremental = 0;
%% MATLAB SOLVER
% Set up the solver
problem.objective = @(M) (1/M^2)*(((2+gm1*M^2)/gp1)^(gp1/gm1))-ARatio^2; % Objective function
problem.solver = 'fzero'; % Find the zero
problem.options = optimset(@fzero); % Default options
% Solve subsonic root
problem.x0 = [1e-6 1]; % Subsonic solver bounds
Msub = fzero(problem); % Solve for subsonic M
problem.x0 = [1+1e-6 50]; % Supersonic solver bounds
Msup = fzero(problem); % Solve for supersonic M
% Print solutions to command window
fprintf('==== MATLAB SOLVER ====\n');
fprintf('Msub: %3.4f\n',Msub);
fprintf('Msup: %3.4f\n',Msup);
fprintf('=======================\n\n');
  4 comentarios
Jim Riggs
Jim Riggs el 1 de Oct. de 2019
Thank you. It works.
Matlab Answers 20190930b.JPG

Iniciar sesión para comentar.

Respuestas (1)

David Hill
David Hill el 1 de Oct. de 2019
function [Msub,Msup] = sub_super(ARatio)%ARatio needs to be >1
g = 1.4;
gm1 = g-1;
gp1 = g+1;
Msub=zeros(size(ARatio));
Msup=zeros(size(ARatio));
for i=1:length(ARatio)
problem.objective = @(M) (1/M^2)*(((2+gm1*M^2)/gp1)^(gp1/gm1))-ARatio(i)^2;
problem.solver = 'fzero';
problem.options = optimset(@fzero);
problem.x0 = [1e-6 1];
Msub(i) = fzero(problem);
problem.x0 = [1+1e-6 50];
Msup(i) = fzero(problem);
end
plot(ARatio,Msub);
hold on
plot(ARatio,Msup);
end

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by