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!