How to write the code in Matlab for the the double summation attached below.
2 次查看(过去 30 天)
显示 更早的评论
回答(2 个)
Torsten
2023-6-10
移动:Torsten
2023-6-10
n = 5;
m = 10;
p = rand(n,m);
C = rand(1,m);
dt = 0.2;
F1 = dt*sum(sum(C.*p))
2 个评论
Image Analyst
2023-6-10
@Bijaya Das To learn other fundamental concepts, invest 2 hours of your time here:
RANGA BHARATH
2023-6-12
Question: How to write the code to perform double summation (for the equation attached)?
Solution:
According to the provided equation, it can be clearly seen that 'C' is a one-dimensional vector (column or row vector) of length m and 'p' is a 2D array with shape (n,m) or (m,n). One of the approaches is to use normal matrix multiplication for the inner sum and then use 'sum' function for outer sum.
Assumptions:
- Let us assume C as a column vector of shape (m,1) and p as a 2D matrix of shape (n,m).
- Here, I'm using integers to perform this task as it would be easy to understand.
- And the values taken are: m = 3, n = 2, range of integers used = 1 to 5, deltat = 0.5.
Code:
n = 3;
m = 2;
p = randi([1,5],n,m)
C = randi([1,5],m,1)
deltat = 0.5;
temp = p*C*deltat
f1 = sum(temp,1)
Links to Documentation:
- Here is the link to the documentation of 'randi' function which generates random integers of between specified range and of specified shape https://www.mathworks.com/help/matlab/ref/randi.html..
- Here is the link to the documentation of 'sum' function Sum of array elements - MATLAB sum (mathworks.com).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!