plot a function having two variables with unequal elements

1 visualización (últimos 30 días)
Debasish Mishra
Debasish Mishra el 7 de Abr. de 2020
Respondida: the cyclist el 7 de Abr. de 2020
hello
i have a fuction as follows
XT=k*L*pitch;
where L contains 100 elements and pitch contains 5 elements. k also contains 5 elements.
i want to create this function and also do plot(L,XT).
it will be a great help if anyone can help me in this.
  4 comentarios
Walter Roberson
Walter Roberson el 7 de Abr. de 2020
Assuming L is 1 x 100 and k is 1 x 5, then k.' * L would be (1 x 5 transposed) * (1 x 100) = 5 x 1 * 1 x 100 -> 5 x 100.
Now you want to multiply that by 1 x 5 pitch. If you pre-multiply, pitch * (k.' * L) then that would be 1 x 5 * 5 x 100 which would give 1 x 100, but you want 5 x 100 or 100 x 5 output. If you post-multiply then that would be 5 x 100 * 1 x 5 and you can only get that to work with some transposes, but you are going to end up with 100 x 1 or 1 x 100 again.
You will need to show us the mathematical form of the calculation you want.
Debasish Mishra
Debasish Mishra el 7 de Abr. de 2020
thanks walter for your timely response.
here i am attaching my matlab syntax for easy understanding.
pitch=[30 40 50 60 70] ;
L=linspace(1,1000);
N11=sqrt(delta1).*U1.^2.*sqrt((pi*a)./(pitch.*W1)).*exp(-pitch.*W1/a);
D=a*V^3.*K1.^2;
kpq1=N11./D;
XT1=(2.*kpq1.^2*Rb.*L)./(pitch.*B1);
plot(L,XT1)
so basically except L and pitch all are constants.For each element of pitch the code calculates 100 values of XT1.
The plot function should plot 5 different curves for each element of pitch.I tried using for loop but failed.
1st curve should denote for pitch =30,second for pitch =40 and so on.
thanks in advance.

Iniciar sesión para comentar.

Respuestas (1)

the cyclist
the cyclist el 7 de Abr. de 2020
Merging the code you've provided with Walter's comments:
pitch=[30 40 50 60 70]' ;
L=linspace(1,1000);
delta1 = 1;
W1 = 1;
U1 = 1;
a = 1;
V = 1;
K1 = 1;
Rb = 1;
B1 = 1;
N11=sqrt(delta1).*U1.^2.*sqrt((pi*a)./(pitch.*W1)).*exp(-pitch.*W1/a);
D=a*V^3.*K1.^2;
kpq1=N11./D;
XT1=(2.*kpq1.^2*Rb.*L)./(pitch.*B1);
figure
h = plot(L,XT1,'.-');
set(h,'MarkerSize',16)
A couple things to note.
First, there are five curves there. Presumably they will be separated when you put in your actual constants.
As Walter suggested, I have reoriented pitch so that it is 5x1 instead of 1x5. This is the crucial element you need to understand. If you try to multiply
rand(1,5) .* rand(1,100)
then you are going to get a dimension mismatch error. But if you do
rand(5,1) .* rand(1,100)
then MATLAB is going to use implicit expansion, and effectively make both of those arrays into 5x100 arrays before multiplying them. That is what happens in the calculation of XT1 in the code I posted.
Then, the syntax of the plot command will plot five lines (with 100 points each) when you input the 5x100 array. (I used large dots to illustrate this.)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by