How to sum the product between a matrix and 2 vectors

조회 수: 1 (최근 30일)
Sara  Crosetto
Sara Crosetto 2020년 12월 17일
답변: Karan Singh 2025년 1월 31일
I need to solve a system of differential equation written as:
For each equation I should solve a summation like:
where K_Br is a matrix previously calculated and n is a vector as the solution of the differential equation system.
For example, for i=3:
I wrote the system of differential equation as:
function ndot = System_ni (t,n)
ndot = zeros(M,1);
ndot(1) = -n(1)*sum(K_Br(1,1:M)*n(1:M));
for i = 2:M
ndot(i) = 1/2*sum(K_Br(1:i-1,i-1:1)*n(i-1:1)*n(1:i-1))-n(i)*sum(K_Br(i,1:M)*n(1:M));
end
end
but summation seems not to work.
Thank you in advance for any help.
  댓글 수: 3
Sara  Crosetto
Sara Crosetto 2020년 12월 18일
I reported the initial equation wrong.
Actually, the equation is:
VBBV
VBBV 2024년 4월 8일
@Sara Crosetto the terms in equation shown are dependent on another implicit summing variable i
You need two for loops instead of one for such summation to work.

댓글을 달려면 로그인하십시오.

답변 (1개)

Karan Singh
Karan Singh 2025년 1월 31일
Hi Sara,
I think you are not performing the element-wise operation correctly. How about using " .* " instead of " * " for element-wise multiplication? This MATLAB answer might be of help:What does mean .* and ' ? - MATLAB Answers - MATLAB Central for you to carry out the process.

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by