forked from Gjjj74833/RTG-REU-UA-Summer-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fit_CpCt.m
111 lines (86 loc) · 2.53 KB
/
fit_CpCt.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
clear
clc
% This script read the .txt file containing the data for
% power coefficient and thrust coefficient and find the
% best fit surface
%
% author: Yihan Liu
% date: 9/1/2023
% read the data
fid = fopen('Cp_Ct.NREL5MW.txt', 'r');
% skip to the line containing pitch_angles
for i = 1:4
fgets(fid);
end
% read data for pitch angles
pitch_angles = fscanf(fid, '%f', inf)';
fgets(fid);
% read data for TSR values
TSR_values = fscanf(fid, '%f', inf)';
% skip to the line containing the power coefficient
for i = 1:5
fgets(fid);
end
% read data for the power coefficient
C_p = fscanf(fid, '%f', [length(pitch_angles), length(TSR_values)])';
% skip to the line containing the thrust coefficient
for i = 1:4
fgets(fid);
end
% read data for the thrust coefficient
C_t = fscanf(fid, '%f', [length(pitch_angles), length(TSR_values)])';
% close the file
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fit the data
[x, y] = meshgrid(pitch_angles, TSR_values);
angle_data = x(:);
TSR_data = y(:);
Cp_data = C_p(:);
Ct_data = C_t(:);
ft = fittype('poly55');
% fit the power coefficient
[surfaceFitCp, gofCp] = fit([angle_data, TSR_data], Cp_data, ft);
% fit the thrust coefficient
[surfaceFitCt, gofCt] = fit([angle_data, TSR_data], Ct_data, ft);
% display results for C_p
disp('Fit parameters for C_p:');
disp(surfaceFitCp);
disp('Goodness of fit for C_p:');
disp(gofCp);
% display results for C_t
disp('Fit parameters for C_t:');
disp(surfaceFitCt);
disp('Goodness of fit for C_t:');
disp(gofCt);
% Generate mesh for visualization
[X, Y] = meshgrid(linspace(min(pitch_angles), max(pitch_angles), 100), ...
linspace(min(TSR_values), max(TSR_values), 100));
% Evaluate the fitted surfaces
Z_Cp = feval(surfaceFitCp, X, Y);
Z_Ct = feval(surfaceFitCt, X, Y);
% Create a new figure for Cp
figure;
hold on;
surf(X, Y, Z_Cp, 'FaceAlpha', 0.5, 'EdgeColor', 'none'); % Fitted surface
scatter3(angle_data, TSR_data, Cp_data, 'ro'); % Data points
title('Fitted Surface and Data Points for Cp');
xlabel('Pitch Angle');
ylabel('TSR');
zlabel('Cp');
hold off;
grid on; % Enable grid
view(3); % Set to 3D view
% Create a new figure for Ct
figure;
hold on;
surf(X, Y, Z_Ct, 'FaceAlpha', 0.5, 'EdgeColor', 'none'); % Fitted surface
scatter3(angle_data, TSR_data, Ct_data, 'bo'); % Data points
title('Fitted Surface and Data Points for Ct');
xlabel('Pitch Angle');
ylabel('TSR');
zlabel('Ct');
hold off;
grid on; % Enable grid
view(3); % Set to 3D view