how to make nxn matrix

62 ビュー (過去 30 日間)
WonJong We
WonJong We 2021 年 4 月 14 日
コメント済み: WonJong We 2021 年 4 月 15 日
I want to make nxn matrix by follweing rule
n=input
first and last is 1
how can do it?
This is the original formula.
clc;
n=input
A=(n ; n)???
  2 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 14 日
Sorry, that image is too faint to read.
WonJong We
WonJong We 2021 年 4 月 14 日
Thank you for the information.
I will change!!

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

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 14 日
n = 7
n = 7
d = ones(1,n-2)/2;
M = zeros(n,n) + diag([0,d],+1) + diag([d,0],-1);
M(1) = 1; M(end) = 1;
M
M = 7×7
1.0000 0 0 0 0 0 0 0.5000 0 0.5000 0 0 0 0 0 0.5000 0 0.5000 0 0 0 0 0 0.5000 0 0.5000 0 0 0 0 0 0.5000 0 0.5000 0 0 0 0 0 0.5000 0 0.5000 0 0 0 0 0 0 1.0000
  9 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 15 日
n=3;
%n=input ('put your n=')
d = ones(1,n-1)/2;
M = zeros(n+1,n+1) + diag([0,d],+1) + diag([d,0],-1);
M(1) = 1; M(end) = 1;
M
M = 4×4
1.0000 0 0 0 0.5000 0 0.5000 0 0 0.5000 0 0.5000 0 0 0 1.0000
T = [sym('T0') ; sym('T',[n 1]) ]
T = 
Tvals = T;
Tvals(1) = 500;
Tvals(n+1) = 300; %Tn is at position n+1
MT = subs(M*T, T, Tvals)
MT = 
eqn = MT == T
eqn = 
sol = solve(eqn)
sol = struct with fields:
T0: [1×1 sym] T1: [1×1 sym] T2: [1×1 sym] T3: [1×1 sym]
sol.T0
ans = 
500
sol.T1
ans = 
sol.T2
ans = 
sol.T3
ans = 
300
WonJong We
WonJong We 2021 年 4 月 15 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear Algebra についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by