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
Show older comments
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
Answers (1)
William Rose
on 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 Comments
Tapuwa Shambira
on 8 Apr 2022
William Rose
on 8 Apr 2022
@Tapuwa Shambira, Please, please be careful when posting questions. I spent a lot of time trying to decipher your code, and now you say you did not mean to post it. This wastes the time of the volunteers here who are trying to help one another. Thank you.
I do not understand your re-stated question. Please post the Matab code which does not work the way you expect it to work. If you get an error message, state the error. If you do not have any Matlab code, please generate some, and try it, before asking for assistance. Inlcude the output, even if it is just an error message. If it is completely impossible for you to write any code, then state your quesiton in clear mathematical terms, using un-ambiguous notation. If necessary for clarity, use the equation writing tool above by clicking the Sigma symbol above (Σ). For example:
How can I write a loop that computes power for different angles and cup sizes? The equation I want to evaluate is

I have learned how to use the equation tool by googling: "how to make a fraction in Latex", "how to make a square root in Latex", etc. Please double check your equations for correctness before submitting your question. This will help you get better help.
Tapuwa Shambira
on 8 Apr 2022
William Rose
on 8 Apr 2022
If I understand your problem correctly, you want to create a four-dimensional array of force values: F(i,j,k,m), where, for example, i, j, k, m correspond to different values of height, diameter, velocity, and angle, respectively. Is that correct?
William Rose
on 8 Apr 2022
Here is code to compute force (F) for the different combinaitons of height, diameter, velocity, and angle.
CD1=2.3; %concave coeffcicient of drag
CD2=1.2; %convex coeffcicient of drag
rho=1000; % water density (kg/m^3)
Na=25; a=linspace(0,360,Na); %angle in degrees
Nh=9; h=linspace(0.122,0.208,Nh); %height
Nd=6; d=linspace(0.05,0.075,Nd); %diameter
Nv=5; v=linspace(1,6,Nv); %velocity
for i=1:Na
for j=1:Nh
for k=1:Nd
for m=1:Nv
if cosd(a(i))>=0
F(i,j,k,m)=0.5*CD1*rho*h(j)*d(k)*v(m)*cosd(a(i));
else
F(i,j,k,m)=0.5*CD2*rho*h(j)*d(k)*v(m)*cosd(a(i));
end
end
end
end
end
It runs without error. It uses the concave coefficient when the velocity is positive, and it uses the convex coefficient when the velocity is negative. It uses 25 angles (every 15 degrees), 9 heights (every 0.011, approximately), 6 diameters (every 0.005), and 5 velocities (every 1.0). Therefore F() has dimensions 25x9x6x5.
Tapuwa Shambira
on 9 Apr 2022
William Rose
on 9 Apr 2022
@Tapuwa Shambira, you're welcome. Good luck with your work.
Categories
Find more on Mathematics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!