Error plotting fzero function - "Operands to the || and && operators must be convertible to logical scalar values"
Show older comments
Good Day!
I am trying to plot the solution of an equation using fzero function but getting the error - "Operands to the || and && operators must be convertible to logical scalar values". Can anyone please help me out.
The code is
clc;
clear all;
format short;
Throat_Diameter=2.8;
Exit_Diameter=5.76;
G=1.4;
Throat_Area=3.14159265.*(10.^(-6)).*((Throat_Diameter).^2)/4;
Exit_Area_inMeter=3.14159265.*(10.^(-6)).*((Exit_Diameter).^2)/4;
Diverging_Length= input('Enter the length of diverging section in mm: )' );
Distance_from_throat=linspace(1,Diverging_Length,50);
Section_Diameter=Throat_Diameter+((Exit_Diameter-Throat_Diameter)*Distance_from_throat)/Diverging_Length;
Section_Area=3.14159265.*(10.^(-6)).*((Section_Diameter).^2)/4;
ARatio=Section_Area/Throat_Area;
problem.objective = @(M) (1/M.^2).*(((2+(G-1).*M.^2)/(G+1)).^((G+1)/(G-1)))-ARatio.^2; % Objective function
problem.solver = 'fzero'; % Find the zero
problem.options = optimset(@fzero); % Default options
% Solve supersonic root
problem.x0 = [1+1e-6 50]; % Supersonic solver bounds
M_Local = fzero(problem); % Solve for supersonic M
plot(Distance_from_throat,M_Local)
The error is:
Operands to the || and && operators must be convertible to logical scalar values.
Error in fzero (line 421)
while fb ~= 0 && a ~= b
Error in PlottingAreaMachRelation (line 23)
M_Local = fzero(problem); % Solve for supersonic M
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!