Azzera filtri
Azzera filtri

Lowest value that fulfills a condition

1 visualizzazione (ultimi 30 giorni)
Hello,
I've a script that takes a long time to run due to the small steps I've set up, but i need precision in the calculations so thats why I need the decimal places.
short version script:
T=0;
W=30000;
while T<=W
theta_tip=theta_tip+0.001;
for i=1:100
T1=int((theta_tip/(y/Rmax))...., y, lim_inf, lim_sup);
T2=int(T1,0,2*pi());
T=1/(2*pi)*T2;
end
end
some of the long story:
theta_tip=0; %degrees - angle of atack of blade tip
T=0; %N - Total produced lift
Up=0; %m/s
Rmax=4;
Rmin=0.5;
nbe=5;
ro=0.8;
chord=0.2;
Omega=42;
Cl_alpha=[6.5044 6.6122 6.7820 7.0986 7.5694];
el_size=(Rmax-Rmin)/nbe; %m - element size in meters
lim_inf=Rmin; %integral inferior limit
lim_sup=lim_inf+el_size; %integral superior limit
syms y
tic
while T<=W
theta_tip=theta_tip+0.00001;
for i=1:nbe
if i==1
lim_inf=lim_inf; %#ok<ASGSL>
lim_sup=lim_inf+el_size;
else
lim_inf=lim_inf+el_size;
lim_sup=lim_inf+el_size;
end
T1=int(1/2*ro*chord*Cl_alpha(i)*((theta_tip/(y/Rmax))*(Omega*y)^2-Up*(Omega*y)), y, lim_inf, lim_sup);
T2=int(T1,0,2*pi());
T=1/(2*pi)*T2;
end
end
toc
[Edit- more variables given] i'll be grateful for any help! thanks!
  3 Commenti
Diogo Nascimento
Diogo Nascimento il 29 Nov 2017
I understand, I'll read those and submit the remaining code, I thought it was best not to put everything in here, but i'll simplify the variables and put it here! thanks for the help!
Diogo Nascimento
Diogo Nascimento il 29 Nov 2017
Modificato: Diogo Nascimento il 29 Nov 2017
theta_tip=0; %degrees - angle of atack of blade tip
T=0; %N - Total produced lift
Up=0; %m/s
Rmax=4;
Rmin=0.5;
nbe=5;
ro=0.8;
chord=0.2;
Omega=42;
Cl_alpha=[6.5044 6.6122 6.7820 7.0986 7.5694];
el_size=(Rmax-Rmin)/nbe; %m - element size in meters
lim_inf=Rmin; %integral inferior limit
lim_sup=lim_inf+el_size; %integral superior limit
syms y
tic
while T<=W
theta_tip=theta_tip+0.00001;
for i=1:nbe
if i==1
lim_inf=lim_inf; %#ok<ASGSL>
lim_sup=lim_inf+el_size;
else
lim_inf=lim_inf+el_size;
lim_sup=lim_inf+el_size;
end
T1=int(1/2*ro*chord*Cl_alpha(i)*((theta_tip/(y/Rmax))*(Omega*y)^2-Up*(Omega*y)), y, lim_inf, lim_sup);
T2=int(T1,0,2*pi());
T=1/(2*pi)*T2;
end
end
toc
I think this is all that's necessary!

Accedi per commentare.

Risposta accettata

Star Strider
Star Strider il 29 Nov 2017
Use numeric integration rather that the Symbolic Math Toolbox.
With your Symbolic Math Toolbox code, when I ran it on my laptop, I got:
Elapsed time is 110.680337 seconds.
Running this loop on my laptop:
tic
while T<=W
theta_tip=theta_tip+0.00001;
for i=1:nbe
if i==1
lim_inf=lim_inf; %#ok<ASGSL>
lim_sup=lim_inf+el_size;
else
lim_inf=lim_inf+el_size;
lim_sup=lim_inf+el_size;
end
T1(i)=integral(@(y) 1/2*ro*chord*Cl_alpha(i)*((theta_tip/(y/Rmax))*(Omega*y)^2-Up*(Omega*y)), lim_inf, lim_sup, 'ArrayValued',1);
T = T1(i);
end
end
toc
I got:
Elapsed time is 4.579191 seconds.
The only difference was in using the anonymous function with integral.
Also, the ‘T2’ and ‘T’ calculations are redundant, since ‘T2’ essentially multiplies ‘T1’ by ‘2*pi’, then ‘T’ divides ‘T2’ by ‘2*pi’. So ‘T’ is simply ‘T1’. I added the subscripts so that now ‘T1’ is saved as a vector for each value of ‘Cl_alpha’.
  2 Commenti
Diogo Nascimento
Diogo Nascimento il 15 Dic 2017
that did the trick! thank you!!
Star Strider
Star Strider il 15 Dic 2017
As always, my pleasure!

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by