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 Comments

Sorry, that image is too faint to read.
Thank you for the information.
I will change!!

Sign in to comment.

 Accepted Answer

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 Comments

Thank you so much!!
and... how to make T_0:T_n matrix??
I tried
syms T
B=(T(0):T(n))
A=B(:)
but error
n = 5
n = 5
syms T0
syms T [n 1]
T = [T0; T]
T = 
Thank you so much!!
n=5
syms T0
syms T [n 1]
T = [T0 ; T]
error (Invalid variable name.)
hum...
T = [sym('T0') ; sym('T',[n 1]) ]
WonJong We
WonJong We on 15 Apr 2021
Edited: WonJong We on 15 Apr 2021
Thank you very much!!!
clear all; clc; close all;
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]) ]
T0=500;
T(n)=300;
T=M*T
than...
T =
T0
T0/2 + 150
T1/2 + T3/2
T3
The values of T2 and T1 are presented as variables.
How do I get a number?
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
Thank you!

Sign in to comment.

More Answers (0)

Categories

Find more on Geology in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!