integral of a matrix

조회 수: 115 (최근 30일)
raha ahmadi
raha ahmadi 2021년 6월 19일
댓글: raha ahmadi 2021년 6월 19일
I want to take the integral of an exponetial of a matrix but I got this error and dont know how fix it:
'Unable to perform assignment because the indices on the left side are not compatible with the size of
the right side.
Error in Untitled7 (line 12)
ggg(ss)=integral(fun,0,T,'ArrayValued',true);'
thanks in advance
clc
clear
close all
M=ones(3,3);
Dmat=[1;2;3];
fun=@(t)expm(-M.*t)*Dmat;
T=1e-2;
g=integral(fun,0,T,'ArrayValued',true);
  댓글 수: 4
Walter Roberson
Walter Roberson 2021년 6월 19일
And when you do not have that (ss) in there, then no error message is emitted.
I notice your tags mention expm, which is the matrix exponential, but your code uses exp() which is element-by-element exponential.
raha ahmadi
raha ahmadi 2021년 6월 19일
two mistakes in 5 lines code! good for me !!
I m really sorry and thank you very much. I m very tired and ...I corrected it
I hope you best wishes

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 19일
format long g
M = ones(3,3);
Dmat = [1;2;3];
fun = @(t)expm(-M.*t)*Dmat;
T = 1e-2;
g = integral(fun,0,T,'ArrayValued',true);
g
g = 3×1
0.00970297763432788 0.0197029776343279 0.0297029776343279
  댓글 수: 1
raha ahmadi
raha ahmadi 2021년 6월 19일
I appreciate your attention and hope you all best

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

추가 답변 (1개)

Scott MacKenzie
Scott MacKenzie 2021년 6월 19일
You note:
I want to take the integral of an exponetial of a matrix
But,
exp(-M.*t)*Dmat;
is a vector, not a matrix. Try using the dot operator in your function definition:
exp(-M.*t).*Dmat;
  댓글 수: 1
raha ahmadi
raha ahmadi 2021년 6월 19일
sorry you are right but in fact I need to calculate the integal of a multiplication of a exponensial of a matrix by a column vector "Dmat". Its a matrix multiplication not an element-wise multiplication.
Best regards

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by