how to make nxn matrix
40 次查看(过去 30 天)
显示 更早的评论
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
2021-4-14
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 个评论
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!