How can write this equation in matlab?

1 回表示 (過去 30 日間)
S AsZ 2023 年 9 月 15 日

Hi everyone. Can you guide me to write the code of this equation? In this equation Rcl is a variable, qqdc is a binary variable, and rdc and Rdk are parameters with specified values.

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

採用された回答

Nathan Hardenberg 2023 年 9 月 15 日
You do not specify what l is so I will disregard it at first. Also your variables are vectors/matricies if I see that correctly. I assume K is the index of the last element in the vector. Thats why I'm writing qqdc(2:end) for example. Be sure to also check the prod()-function to know what it is doing.
% variables / vectors
qqdc = [1; 1; 1];
rdc = [2.1; 2.2; 2.3];
Rdk = [3.1; 3.2; 3.3];
% equation
Rcl = (qqdc(1)*rdc(1)*Rdk(1)) + ...
((1 - qqdc(1)*rdc(1)*Rdk(1)) * ...
(1 - prod(1 - qqdc(2:end).*rdc(2:end).*Rdk(2:end)))) % using the .* operator to do elementwise product
Rcl = 220.3178
Now you could throw this in a for loop and calculate for every l value. Not that great of a way. So here I'm trying to do it with vector operations. Be aware that this is harder to wrap your head around (in my opinion) and because I don't have examples to test with I can't really check if it is correct the way you want it to be.
% variables / vectors / matrecies
qqdc = [1 1; 1 1; 1 1] % with k rows and l colums
qqdc = 3×2
1 1 1 1 1 1
rdc = [2.1 2.5; 2.2 2.6; 2.3 2.7] % with k rows and l colums
rdc = 3×2
2.1000 2.5000 2.2000 2.6000 2.3000 2.7000
Rdk = [3.1; 3.2; 3.3] % with k rows
Rdk = 3×1
3.1000 3.2000 3.3000
Rcl = (qqdc(1,:).*rdc(1,:).*Rdk(1)) + ... % I am assuming an elementwiese product here
((1 - qqdc(1,:).*rdc(1,:).*Rdk(1)) .* ...
(1 - prod(1 - qqdc(2:end,:).*rdc(2:end,:).*Rdk(2:end,:))))
Rcl = 1×2
220.3178 391.8331

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

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by