フィルターのクリア

How to automate the matrix-vector multiplication using the index of a vector?

3 ビュー (過去 30 日間)
Romio
Romio 2022 年 7 月 29 日
コメント済み: Matt J 2022 年 7 月 29 日
I have the following
m = 50;
a = 5
b = 2
c = 2
J = @(t,y) [diag(a*ones(1,m)) + diag(b*ones(1,m-1),1) + diag(c*ones(1,m-1),-1)];
I want to obtain the function/function handle (which takes (t,y) as argument) that gives essentially
A = @(t,y) [J*y]
but I want the output to be in terms of the elements of the vector y, these are y(1), y(2), ..., y(m). That is
[5*y(1) + 2*y(2);
2*y(1) + 5*y(5) + 2*y(3);
.
.
.
2*y(m-1) + 5*y(m)]
  1 件のコメント
Matt J
Matt J 2022 年 7 月 29 日
t isn't used anywhere in your expressions. What is it's role?

サインインしてコメントする。

回答 (1 件)

Matt J
Matt J 2022 年 7 月 29 日
m = 50;
a = 5;
b = 2;
c = 2;
J = [diag(a*ones(1,m)) + diag(b*ones(1,m-1),1) + diag(c*ones(1,m-1),-1)];
syms y [m,1]
expression = J*y
expression = 
  2 件のコメント
Romio
Romio 2022 年 7 月 29 日
Thanks a lot Matt. The problem is that I can't use the sympolic toolbox in my application (ode solver)
Matt J
Matt J 2022 年 7 月 29 日
If you can't use the symbolic toolbox, your question doesn't make sense because you've asked for a symbolic result. If you don't need a symbolic result, then J*y already gives you that.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumber Theory についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by