Intergrating using For Loop! HELP!
Mostrar comentarios más antiguos
So, I have this assignment when I am supposed to find the distribution of certain values along a surface. The data was provided to calculate all the values needed.
this is a picture of the assignment 

and this is my code..
clc;
clear;
%Reading data
fid=fopen('airfoil.dat','r');
m=fscanf(fid,'%d',1);
for i=1:m+1
x(i)=fscanf(fid,'%f',1);
y(i)=fscanf(fid,'%f',1);
cf(i)=fscanf(fid,'%f',1);
cp(i)=fscanf(fid,'%f',1);
end
%Loop for panel calculation
%lengths (ds) orintation angle (theta)
for i=1:m
ds(i)=sqrt((x(i+1)-x(i))^2+(y(i+1)-y(i))^2);
theta(i)= atan2((y(i+1)-y(i)),(x(i+1)-x(i)));
end
%CFx and CFy calculations
for i=1:m;
CFy_p=(-1)*cp(i)*cos(theta(i))*ds(i);;
CFx_p=(-1)*cp(i)*sin(theta(i))*ds(i);;
CFy_s=(-1)*cf*sin(theta(i))*ds(i);;
CFx_s=(-1)*cf*cos(theta(i))*ds(i);;
end
%CL and CD calculations
alpha=5
CL=((CFy_p+CFy_s)*cos(alpha))-((CFx_p+CFx_s)*sin(alpha));
CD_pressure=CFy_p*sin(alpha)+CFx_p*cos(alpha);
CD_friction=CFy_s*sin(alpha)+CFx_s*cos(alpha);
CD_total= CD_pressure+CD_friction;
%plots
plot(x,y); axis equal;
title('airfoil');
xlabel('x');
ylabel('y');
plot(x,cp);
set(gca,'ydir','revers');
title('cp distribution');
xlabel('x');
ylabel('cp');
plot(x,cf);
title('cf distribution');
xlabel('x');
ylabel('cf');
I know that the first part and last part of the code is correct but I'm not sure about the middle part.. Final values were given to us and when I compared it's not the same.
this should be thie final results
alpha=5 degrees
Cl=0.636
Cd=0.01011
please help!
data sheet attatched
2 comentarios
Jan
el 31 de En. de 2019
Look at this:
for i=1:m;
CFy_p=(-1)*cp(i)*cos(theta(i))*ds(i);;
CFx_p=(-1)*cp(i)*sin(theta(i))*ds(i);;
CFy_s=(-1)*cf*sin(theta(i))*ds(i);;
CFx_s=(-1)*cf*cos(theta(i))*ds(i);;
end
The variables are overwritten in each iteration. This cannot be useful for solving an integral. You need a sum like a = a + b.
TF
el 31 de En. de 2019
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Logical en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
