Intergrating using For Loop! HELP!
이전 댓글 표시
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
Jan
2019년 1월 31일
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
2019년 1월 31일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
