how to make nxn matrix
31 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
WonJong We
am 14 Apr. 2021
Kommentiert: WonJong We
am 15 Apr. 2021
I want to make nxn matrix by follweing rule
n=input
first and last is 1
how can do it?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/583416/image.png)
This is the original formula.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/583541/image.jpeg)
clc;
n=input
A=(n ; n)???
2 Kommentare
Akzeptierte Antwort
Walter Roberson
am 14 Apr. 2021
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
9 Kommentare
Walter Roberson
am 15 Apr. 2021
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
T = [sym('T0') ; sym('T',[n 1]) ]
Tvals = T;
Tvals(1) = 500;
Tvals(n+1) = 300; %Tn is at position n+1
MT = subs(M*T, T, Tvals)
eqn = MT == T
sol = solve(eqn)
sol.T0
sol.T1
sol.T2
sol.T3
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Mathematics finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!