Solving a set of complex trig equation
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Irtiza Masrur
am 25 Nov. 2024
Bearbeitet: Walter Roberson
am 27 Nov. 2024
Hello,
I have a very complex set of trig equations:
eqns1 = (-rake + (R_values(i)*(d/2))*deg2rad(skew)*tan(p) + (0.5 * chord_len(i) - x_c(1)) * sin(p) + y_u_L(1) * cos(p)) == xp(i*200);
eqns2 = R_values(i)*(d/2) * sind(skew -(180 * ((0.5 * chord_len(i) - x_c(1)) * cos(p) - y_u_L(1) * sin(p))) /(pi * R_values(i)*(d/2))) == yp(i*200);
eqns3 = R_values(i)*(d/2) * cosd(skew -(180 * ((0.5 * chord_len(i) - x_c(1)) * cos(p) - y_u_L(1) * sin(p))) /(pi * R_values(i)*(d/2))) == zp(i*200);
Attaching a picture of the equations for convineince of viewing.

Here I have named iG => rake, θs => skew, and θnt => p in my MATLAB script, The unknowns are: rake, p, and skew. All the other values are known.
I have tried using solve, vpasolve, and fsolve. solve and vpasolve generates an emptry structure for S.

Code of the loop that solves the equations:
for i = 1:9
% Calculate airfoil properties
chord_len = chord_length_at_R * d;
max_c = max_camber_at_R .* chord_len;
max_th = max_thickness_at_R * d;
cam = -cam_d * max_c(i);
th = th_d * max_th(i);
x_c = X_c * chord_len(i);
theta1 = atan2(der_y, 1);
y_u_L = cam + th .* cos(theta1);
% Define equations
eqns1 = (-rake + (R_values(i)*(d/2))*deg2rad(skew)*tan(p) + ...
(0.5 * chord_len(i) - x_c(1)) * sin(p) + y_u_L(1) * cos(p)) == xp(i*200);
eqns2 = R_values(i)*(d/2) * sind(skew - ...
(180 * ((0.5 * chord_len(i) - x_c(1)) * cos(p) - y_u_L(1) * sin(p))) / ...
(pi * R_values(i)*(d/2))) == yp(i*200);
eqns3 = R_values(i)*(d/2) * cosd(skew - ...
(180 * ((0.5 * chord_len(i) - x_c(1)) * cos(p) - y_u_L(1) * sin(p))) / ...
(pi * R_values(i)*(d/2))) == zp(i*200);
% Solve equations
try
S = vpasolve(simplify([eqns1, eqns2, eqns3]), [p, skew, rake], [pitch(i),0, skew_angle_at_R(i)]); % With initial guess
if isempty(S)
disp(['No solution for section ', num2str(i)]);
else
rake_sol = double(S.rake);
p_sol = double(S.p);
skew_sol = double(S.skew);
fprintf('Section %d: Rake = %.4f, P = %.4f, Skew = %.4f\n', i, rake_sol, p_sol, skew_sol);
end
catch ME
disp(['Error solving section ', num2str(i)]);
disp(ME.message);
end
end
And with fsolve I can only converge the first two sections.

Code of the loop that solves the equations:
for i = 1:n
% Scale airfoil data for current section
chord_len = chord_length_at_R * d;
max_c = max_camber_at_R .* chord_len;
max_th = max_thickness_at_R * d;
cam = cam_d * max_c(i);
th = th_d * max_th(i);
x_c = X_c * chord_len(i);
theta1 = atan2(der_y, 1);
y_u_L = cam + th .* cos(theta1);
% Define equations for fsolve
fun = @(vars) [
(-vars(2) + (R_values(i) * (d / 2)) * vars(3) * tan(vars(1)) + (0.5 * chord_len(i) - x_c(1)) * sin(vars(1)) + y_u_L(1) * cos(vars(1))) - xp(i * 200);
R_values(i) * (d / 2) * sind(vars(3) - (180 * ((0.5 * chord_len(i) - x_c(1)) * cos(vars(1)) - y_u_L(1) * sin(vars(1)))) / (pi * R_values(i) * (d / 2))) - yp(i * 200);
R_values(i) * (d / 2) * cosd(vars(3) - (180 * ((0.5 * chord_len(i) - x_c(1)) * cos(vars(1)) - y_u_L(1) * sin(vars(1)))) / (pi * R_values(i) * (d / 2))) - zp(i * 200)
];
% Use pitch, skew_angle_at_R, and rake as initial guesses
initial_guess = [pitch(i),0, skew_angle_at_R(i)];
% Solve using fsolve
options = optimoptions('fsolve', 'Display', 'none', 'MaxIterations', 10000, 'MaxFunctionEvaluations', 20000);
[solution, fval, exitflag] = fsolve(fun, initial_guess, options);
% Handle non-convergence
if exitflag <= 0
fprintf('fsolve did not converge for section %d. Trying alternative guesses...\n', i);
alt_guesses = [rand(1, 3); [pitch(i),0, skew_angle_at_R(i)]]; % Use random or skew-related guesses
for j = 1:size(alt_guesses, 1)
[solution, fval, exitflag] = fsolve(fun, alt_guesses(j, :), options);
if exitflag > 0
break;
end
end
end
% Store solutions
if exitflag > 0
solutions(i, :) = solution;
else
fprintf('Failed to converge for section %d even with alternative guesses.\n', i);
end
end
I would really appreacite any help on this as I've been stuck on this for some time. I know that these equations are highly non-linaer which is why MATLAB is probably having a hard time solving this, but I am not sure how else to approach this problem.
2 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Airfoil tools finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!