Comparing values of a vector

6 visualizaciones (últimos 30 días)
Rodrigo Pena
Rodrigo Pena el 8 de Abr. de 2021
Comentada: Rodrigo Pena el 9 de Abr. de 2021
Hello All, How are you?
I would like to compare every value of my vector x to the following statement: 0≤x≤P
If x is between 0 and P use this formula to calculate Zc
Zc = (M/P^2)*(2*P.*x - x.^2); % 0≤x≤P
If x is within P and 1, use this formula to calculate Zc
Zc = (M/(1-P)^2)*((1-2*P) + 2*P.*x - x.^2);% P≤x≤1
And I also would like to store the values of Zc from both formulas in a single variable Zc
How can I do this?
Please find the code below:
M = 4/100; % Max Camber.
P = 4/10; % Location of Max Camber.
tmax = 18/100; % Maximum airfoil thickness.
% Mean Camber Line.
x = [0:0.01:1];%chord.
if any(x == 0)
Zc = (M/P^2)*(2*P.*x - x.^2); % 0≤x≤P
else
Zc = (M/(1-P)^2)*((1-2*P) + 2*P.*x - x.^2);% P≤x≤1
end
Thank you in advance !

Respuesta aceptada

Rik
Rik el 9 de Abr. de 2021
This is the easiest way to do it vectorized:
Zc_0_to_P =@(x) (M/P^2)*(2*P.*x - x.^2); % 0≤x≤P
Zc_P_to_1 =@(x) (M/(1-P)^2)*((1-2*P) + 2*P.*x - x.^2);% P≤x≤1
x = 0:0.01:1;
%pre-allocate with NaN so we can spot skipped values (if any)
Zc=NaN(size(x));
L= 0<=x & x<=P;
Zc(L)=Zc_0_to_P(x(L));
L= P<=x & x<=1;%this overlaps with the previous condition for x=P
Zc(L)=Zc_P_to_1(x(L));

Más respuestas (0)

Categorías

Más información sobre Electrical Block Libraries en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by