Matlab array multiplication between numeric and variable array

qi=sym('qi',[1 3]); %define variables q1, q2, q3
prompt = 'enter which point in time you want to find inventory level'; %%user input for time range. ex: 0:6
j = input(prompt)
prompt = 'enter how many basic delivery cycles inventory of item should delivered to retailer i'; %user input for delivery cycles of three retailers ex: [1 2 3]
fri = input(prompt)
p = j
L = bsxfun(@rdivide,j(:),fri) %%find xij matrix which retailer orders at which point. in Xij matrix, 1 means retailer place order and 0 means there is no order from retailer.
R = mod(L,1)
Xij = R <= 0 % print Xij matrix with 1 and 0. three columns for three retailers
B = Xij.*qi % multiplication of Xij with [q1 q2 q3], and i got error message for this matrix as below
if true
>> optimize_vendor
Dr =
[ 1, 2, 3]
M =
6
enter which point in time you want to find inventory level [0:6]
j =
0 1 2 3 4 5 6
enter how many basic delivery cycles inventory of item should delivered to retailer i [1 2 3]
fri =
1 2 3
p =
0 1 2 3 4 5 6
L =
0 0 0
1.0000 0.5000 0.3333
2.0000 1.0000 0.6667
3.0000 1.5000 1.0000
4.0000 2.0000 1.3333
5.0000 2.5000 1.6667
6.0000 3.0000 2.0000
R =
0 0 0
0 0.5000 0.3333
0 0 0.6667
0 0.5000 0
0 0 0.3333
0 0.5000 0.6667
0 0 0
Xij =
7×3 logical array
1 1 1
1 0 0
1 1 0
1 0 1
1 1 0
1 0 0
1 1 1
Error using symengine
Array sizes must match.
Error in sym/privBinaryOp (line 973)
Csym = mupadmex(op,args{1}.s, args{2}.s, varargin{:});
Error in .* (line 294)
X = privBinaryOp(A, B, 'symobj::zip', '_mult');
Error in optimize_vendor (line 24)
B = Xij.*qi
end
Till Xij matrix my code is working perfectly. i need help to multiply Xij array with [q1 q2 q3] array which means first column of Xij with q1, second column with q2 and third column with q3. and finally i need to get sum of each row by variables. ex: q1+q2+q3

3 件のコメント

KSSV
KSSV 2018 年 1 月 23 日
編集済み: KSSV 2018 年 1 月 23 日
Error is different on running the code:
Undefined function or variable 'qi'.
Error in code (line 11)
B = Xij.*qi %
You need to define qi to get help..:)
Mohamed Musni
Mohamed Musni 2018 年 1 月 23 日
編集済み: Mohamed Musni 2018 年 1 月 23 日
that is my problem. i want to define qi in a array such as [q1 q2 q3] and multiply with Xij. i try to define like this qi=sym('qi',[1 3]); and it wont create the array
Birdman
Birdman 2018 年 1 月 23 日
Have you checked my answer?

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

 採用された回答

Birdman
Birdman 2018 年 1 月 23 日

1 投票

i try to define like this i=sym('qi',[1 3]); and it wont create the array
Try it as follows:
syms q1(i) q2(i) q3(i)
q=[q1 q2 q3]

3 件のコメント

Mohamed Musni
Mohamed Musni 2018 年 1 月 23 日
thank you again. this is short and sweet. i figure out a way but not efficient. i separate the columns of the vector and multiply each column by q1, q2 and q3
if true
syms q1 q2 q3 ;
B = Xij(:,1).*q1;
C =Xij(:,2).*q2;
V = Xij(:,3).*q3;
end
Birdman
Birdman 2018 年 1 月 23 日
This works for this example, but for a larger dataset, it will not be efficient.
Mohamed Musni
Mohamed Musni 2018 年 1 月 23 日
yeah thank you for guiding me yesterday and today. just finished my mathematical modelling in matlab. i owe you alot

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by