how to multiply every single number in an array to another array

123 ビュー (過去 30 日間)
Mahmoud Sayed
Mahmoud Sayed 2019 年 5 月 22 日
編集済み: Guillaume 2019 年 5 月 22 日
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));

回答 (1 件)

Guillaume
Guillaume 2019 年 5 月 22 日
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
See compatible array size for details of the technique that this uses.
  2 件のコメント
Mahmoud Sayed
Mahmoud Sayed 2019 年 5 月 22 日
Thanks for your answer, i forgot to clarify one thing, i want to analyse each set of values of M22 based on each value of omega, so this wil gave me all the results of m22 at once is there a way like to be able to show the different 20 values of m22 based on the value of omega once at a time?
Guillaume
Guillaume 2019 年 5 月 22 日
編集済み: Guillaume 2019 年 5 月 22 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by