Checking if my program calculates what is supposed to.

1 view (last 30 days)
Hello all, how are you?
I am trying to write a program that calculates aeroelasticiy stuff. I am not sure if the program is calculating what is supposed to.
The plan is:
1- Guess a value of k between 0 and 1
2- Calculate Ck
3- Calculate f11
4- Calculate f12
5- Calculate f21
6- Calculate f22
7- Calculate the polynomial roots of (p)
8- Pick one of the roots of the polynomial p (let´s say for example the first one)
9- The new value of k is equal to the real part of the root of the polynomial p (first root)
10- Return to step 2 and calculate everthing until k gets convergence.
>> %inputs
a = -1/5;
mu = 2; % 2 ≤ µ ≤ 20
rs = 1/4;
sigma = 1/sqrt(10);
xtheta = 0; % xtheta = 0.0 and 0.2
V = 0.05;
%equations and pre-defining vectors/matrices
k = 0:0.01:1;
r1 = zeros(1,101) ;
r2 = zeros(1,101) ;
r3 = zeros(1,101) ;
r4 = zeros(1,101) ;
for j = 2 : 101;
k(j);
Ck = (0.01365+0.2808.*k.*1i-k.^2./2) / (0.01365+0.3455.*k.*1i-k.^2);
f11 = sigma^2./V.^2 - k.^2./mu + (2*1i.*Ck)/mu;
f12 = (k.*(1i + a.*k) + (2 + 1i.*k.*(1-2*a)).*Ck)/mu;
f21 = (a.*k.^2 - 1i.*k.*(1 + 2*a).*Ck)/mu;
f22 = ((8*mu*rs)./V^2 + 4*1i*(1 + 2*a)*(2*1i - k.*(1 - 2*a)).*Ck - k.*(k - 4*1i + 8*a*(1i + a.*k)))/8*mu;
p = [(rs-xtheta^2) 0 (f22 + f11.*rs - f21.*xtheta - f12.*xtheta) 0 (f11.*f22 - f12.*f21)];
rts = roots(p);
r1(j) = rts(1);
r2(j) = rts(2);
r3(j) = rts(3);
r4(j) = rts(4);
k = imag(r1)
gamma = real (r1)./k;
end
plot(k,gamma);
hold on;
ylabel('γ');
xlabel('k');
hold off;
is this correct ?

Accepted Answer

Mathieu NOE
Mathieu NOE on 2 Dec 2020
hello
yes your code needed some fix
at least I believe I have fixed most recurrence issues in the loop
now there are other issues , like
you said : 9- The new value of k is equal to the real part of the root of the polynomial p (first root)
in your code you're taking the iamginary part , not the real part
if I go with real, k tends to converge to zero whatever the initial value
if I go with imag, k bounces between two values
I guess none of these behaviour is ok
% >> %inputs
a = -1/5;
mu = 2; % 2 ≤ µ ≤ 20
rs = 1/4;
sigma = 1/sqrt(10);
xtheta = 0; % xtheta = 0.0 and 0.2
V = 0.05;
%equations and pre-defining vectors/matrices
k = 0.75;
k_visu(1) = k;
n = 10;% nb of loops
% r1 = zeros(1,n) ;
% r2 = zeros(1,n) ;
% r3 = zeros(1,n) ;
% r4 = zeros(1,n) ;
for j = 2 : n;
Ck = (0.01365+0.2808.*k.*1i-k.^2./2) / (0.01365+0.3455.*k.*1i-k.^2);
f11 = sigma^2./V.^2 - k.^2./mu + (2*1i.*Ck)/mu;
f12 = (k.*(1i + a.*k) + (2 + 1i.*k.*(1-2*a)).*Ck)/mu;
f21 = (a.*k.^2 - 1i.*k.*(1 + 2*a).*Ck)/mu;
f22 = ((8*mu*rs)./V^2 + 4*1i*(1 + 2*a)*(2*1i - k.*(1 - 2*a)).*Ck - k.*(k - 4*1i + 8*a*(1i + a.*k)))/8*mu;
p = [(rs-xtheta^2) 0 (f22 + f11.*rs - f21.*xtheta - f12.*xtheta) 0 (f11.*f22 - f12.*f21)];
rts = roots(p);
% r1(j) = rts(1);
% r2(j) = rts(2);
% r3(j) = rts(3);
% r4(j) = rts(4);
k = real(rts(1));
k_visu(j) = k;
% gamma(j) = real (rts(1))./k;
end
plot(1:n,k_visu);
  42 Comments
Rodrigo Pena
Rodrigo Pena on 11 Dec 2020
Hello Mathieu,
Sorry to bother you again.
Can you do this for the rest of the roots ? I belive that you did just for the first one.
I tried to implement to the other roots but I keep obtaining the same curve with the exacly values of the first root.
Thank you so much !
Mathieu NOE
Mathieu NOE on 11 Dec 2020
hello Rodrigo
here you are :
% I am trying to write a program that calculates aeroelasticiy stuff. I am not sure if the program is calculating what is supposed to.
% The plan is:
% 1- Guess a value of k between 0 and 1
% 2- Calculate Ck
% 3- Calculate f11
% 4- Calculate f12
% 5- Calculate f21
% 6- Calculate f22
% 7- Calculate the polynomial roots of (p)
% 8- Pick one of the roots of the polynomial p (let´s say for example the first one)
% 9- The new value of k is equal to the real part of the root of the polynomial p (first root)
% 10- Return to step 2 and calculate everthing until k gets convergence.
clc
clear all
% % >> %inputs
params.a = -1/5;
params.mu = 2; % 2 ≤ µ ≤ 20
params.rs = 1/4; % NB : rs means r squared (no need to put ^2 in root equation
params.sigma = 1/sqrt(10);
params.xtheta= 0; % xtheta = 0.0 and 0.2;
%equations and pre-defining vectors/matrices
params.k = 0.1;
params.loops = 15;% nb of loops;% nb of loops
root_index = 1:4; % 1:4; % root
%% loop vs V parameter %%
% V has to vary from 0.52 up to 5 in increments of 0.05.
V = (0.52:0.05:5);
for ci = 1:length(root_index)
% main loop / code
for ck = 1:length(V)
params.V = V(ck);
[k_visu,gamma] = mainloop(params, root_index(ci));
k_converged_visu(ci,ck) = k_visu(end);
gamma_converged_visu(ci,ck) = gamma(end);
end
end
figure(1),plot(V,k_converged_visu);grid
title(' k vs V ');
ylabel('k (1st root)');
xlabel('V');
figure(2),plot(V,gamma_converged_visu);grid
title(' gamma vs V ');
ylabel('gamma (1st root)');
xlabel('V');
%%
function [k_visu,gamma] = mainloop(params, root_index)
a = params.a;
mu = params.mu; % 2 ≤ µ ≤ 20
rs = params.rs;
sigma = params.sigma;
xtheta = params.xtheta; % xtheta = 0.0 and 0.2
V = params.V;
%equations and pre-defining vectors/matrices
k = params.k;
loops = params.loops;% nb of loops
k_visu = zeros(1,loops);
for j = 2 : loops
Ck = (0.01365+0.2808.*k.*1i-k.^2./2) / (0.01365+0.3455.*k.*1i-k.^2);
f11 = sigma^2./V.^2 - k.^2./mu + (2*1i.*Ck)/mu; %ok
f12 = (k.*(1i + a.*k) + (2 + 1i.*k.*(1-2*a)).*Ck)/mu; %ok
f21 = (a.*k.^2 - 1i.*k.*(1 + 2*a).*Ck)/mu; %ok
% f22 = ((8*mu*rs)./V^2 + 4*1i*(1 + 2*a)*(2*1i - k.*(1 - 2*a)).*Ck - k.*(k - 4*1i + 8*a*(1i + a.*k)))/8*mu; % not ok - denominator is missing ( )
f22 = ((8*mu*rs)./V^2 + 4*1i*(1 + 2*a)*(2*1i - k.*(1 - 2*a)).*Ck - k.*(k - 4*1i + 8*a*(1i + a.*k)))/(8*mu); %ok
p = [(rs-xtheta^2) 0 (f22 + f11.*rs - f21.*xtheta - f12.*xtheta) 0 (f11.*f22 - f12.*f21)]; %ok
rts = roots(p);
K = sort(rts, 'ComparisonMethod','real');
k = imag(K(root_index));
k_visu(j) = k;
% gamma(j) = real (rts(root_index))./k;
gamma(j) = real (K(root_index))./k;
end
end

Sign in to comment.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!