I'm trying to get my code to run some iterations to calculate different combinations. It needs to run every combination of height and diameter for all angles

1 Ansicht (letzte 30 Tage)
function [area, final_velcotiy]=draftsav(F)
clc
clear
% Properties
CD1=2.3; %concave coeffcicient of drag
CD2=1.2; %convex coeffcicient of drag
p_density=1000; % water density (kg/m^3)
%%
a=360; % angles of rotation you want to test
angle=1:a; % array for angles
gaph=(0.208-0.122)/(a-1); % iterations for the height
gapdiam=(0.075-0.05)/(a-1); % iterations for the cup diameter
h=0.122:gaph:0.208; %height array across the angles stated in a
diam=0.05:gapdiam:0.075; %cup diameter array across angles stated in a
t=zeros(4,a); % creates a zeros matrix that will be used as the frame for how many iterations
t(1,:)=a; % displaying the angles in the first row of the zero matrix
t(2,:)=h; % displaying the heights in the second row of the zero matrix
t(3,:)=diam; % displaying the cup diameters in the third row of the zero matrix
t(4,:)=h.*diam; % displaying the cup area in the fourth row of the zero matrix
gap3=(6-1)/(a-1);
vel=1:gap3:6; %water velocity range
angvel= vel*cos(a); % takes into account the rotating of the rotor which changes the angle at which the water flow will hit
final_velocity=zeros(1,a);%creates a zero matrix
final_velocity(1,:)=abs(angvel); % places the final velocities into the zero matrix
%F1=CD1.*area.*p_density.*0.5.*final_velocity % produces an error, same
%ting without the paranthesis to multiply matrices
for i=1:a
% F(i)=CD1*area(t(i))*p_density*0.5*final_velocity(i)
%F=CD1*area(t(4,:))*p_density*0.5*final_velocity(1,:)
F(i)=CD1*area(i)*p_density*0.5*final_velocity(i)
end
% as it is the code produces a figure output which im assuming is for force
% vs angle but not sure
end

Antworten (1)

William Rose
William Rose am 8 Apr. 2022
Is this function called by another script? If so, give an example.
You said the function creates a figure. Show us the figure, please.
The function's first line is
function [area, final_velcotiy]=draftsav(F)
The line above specifies a function with input variable F and outputs area and final_velcotiy. However, F is treated like an output variable, because it is never read, and a value is assigned to F(i). area is treated as an input, because no value is assigned to it, and it appears on the right hand side of an assignment statement. Value final_velcotiy is treated as an output vairiable, but the spelling in line 1 is incorrect, so it will not work as desired. You must fix all these issues.
The angles appear to be in degrees. Therefore you should use
angvel= vel*cosd(a);
and not
angvel= vel*cos(a);
Good luck.
  7 Kommentare

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by