Mach Number Area Relation Several Inputs

3 次查看(过去 30 天)
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 个评论

请先登录,再进行评论。

回答(1 个)

David Hill
David Hill 2019-10-1
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

类别

Help CenterFile Exchange 中查找有关 Just for fun 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by