how to multiply every single number in an array to another array
38 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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
2 件のコメント
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 Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!