how to multiply every single number in an array to another array
67 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
So I have the following equation and omega is an array, I would like to multiply every single value of omega by the other array which is time, I am unsure on exactly how to proceed i thought of using for statement and then defining every value of omega but that would take up many lines i feel like there is an easier way but I am not sure. SO to add clarity, if we have omega as values 1:1:20 and time as 1:1:20, for example, how do i take each individual value of omega and multiply it by the whole array of time and insert it into the following equation, essentially yieldng 400 different values of M22 hope its clear, thanks in advance
M_22 = ((mass_comp*(sum_f_comp^2) + 0.5*mass_tur*(sum_f_tur^2) + ...
density_shaft*area_shaft*int_f) + (I_Cx*(sum_g_comp^2) + ...
I_Tx*(sum_g_tur^2) + density_shaft*I_S*int_g)) - ...
(((m_u_comp*outer_rad_comp*sum_f_comp) + (m_u_tur* ...
outer_rad_tur*sum_f_tur))*(omega^2)*cos(omega.*time));
0 comentarios
Respuestas (1)
Guillaume
el 22 de Mayo de 2019
Assuming that all the other values are scalar and that you're on R2016b or later, make omega a column vector and time a row vector and .* the two together.
omega = (1:20)'; %column vector, 20x1
time = 1:20; %row vector, 1x20
result = omega .* time %20x20 result
2 comentarios
Guillaume
el 22 de Mayo de 2019
Editada: Guillaume
el 22 de Mayo de 2019
As long as all the other inputs are scalar and that you use the proper dotted operators for operations involving omega and/or times, then you'll get a 20x20 output, with the rows corresponding to omega values, and columns to time values.
With your expression, it looks like
M_22 = ((mass_comp*(sum_f_comp^2) + 0.5*mass_tur*(sum_f_tur^2) + ...
density_shaft*area_shaft*int_f) + (I_Cx*(sum_g_comp^2) + ...
I_Tx*(sum_g_tur^2) + density_shaft*I_S*int_g)) - ...
(((m_u_comp*outer_rad_comp*sum_f_comp) + (m_u_tur* ...
outer_rad_tur*sum_f_tur))*(omega.^2).*cos(omega.*time));
should work.
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!