How can write this equation in matlab?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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
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
rdc = [2.1 2.5; 2.2 2.6; 2.3 2.7] % with k rows and l colums
Rdk = [3.1; 3.2; 3.3] % with k rows
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,:))))
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!