construction of diagonal matrix of functions

조회 수: 1 (최근 30일)
danielle sisserman
danielle sisserman 2020년 11월 28일
편집: Matt J 2020년 11월 28일
I have three functions: f_1, f_2, and f_3.
I want to construct the matrix A for the following linear system:
so the first line of the system will be f_2(x_1) + f_3(x_2) = q_1
second line will be f_1(x_1) + f_2(x_2) + f_3(x_3) = q_2
third line f_1(x_2) + f_2(x_3) + f_3(x_4) = q_3
and so on.
Thank you.

채택된 답변

Matt J
Matt J 2020년 11월 28일
편집: Matt J 2020년 11월 28일
This might be what you want. It assumes that f_1,2,3(x) work element-wise.
function A=func(x)
f1=f_1(x(1:end-1));
f2=f_2(x);
f3=f_3(x(2:end));
A=diag(f1,-1)+diag(f2)+diag(f3,+1);
end

추가 답변 (1개)

Matt J
Matt J 2020년 11월 28일
편집: Matt J 2020년 11월 28일
function A=func(x,n)
e=zeros(1,n-2);
f1=f_1(x);
f2=f_2(x);
f3=f_3(x);
A=toeplitz([f2,f1,e], [f2,f3,e]);
end
  댓글 수: 4
danielle sisserman
danielle sisserman 2020년 11월 28일
Okay, thank you for your reply. I'm not sure how to construct the matrix A using the above function.
I have [x1, x2, ..., x3]. not one x. sorry for not being clear.
so the first line of the system will be f_2(x_1) + f_3(x_2) = q_1
second line will be f_1(x_1) + f_2(x_2) + f_3(x_3) = q_2
third line f_1(x_2) + f_2(x_3) + f_3(x_4) = q_3
and so on.
Thank you.
Matt J
Matt J 2020년 11월 28일
편집: Matt J 2020년 11월 28일
so the first line of the system will be f_2(x_1) + f_3(x_2) = q_1
I'm still not sure what you want, because your drawings and your equations say different things. You're new drawing is equivalent to,
x_1*f_2(alpha) + x_2*f_3(alpha) = q_1
x_1*f_1(alpha) + x_2*f_2(alpha) + x_3*f_3(alpha) = q_2
...

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by