System of Equations with For loop and symbols

2 ビュー (過去 30 日間)
Ryan Mulligan
Ryan Mulligan 2020 年 4 月 23 日
コメント済み: Ryan Mulligan 2020 年 4 月 24 日
sym T
C = .2;
N = 6;
gamma = .1;
delR = (1-C)/N;
Ri = C+(i-1)*delR;
A = sym(zeros(N+1));
B = sym(zeros(N+1,1));
for i = 2:N
A(i,:) = ((1/delR^2-1/(Ri*2*delR)))*T(i-1)-((2/delR^2)+gamma^2)*T(i)+((1/delR^2)+(1/(Ri*2*delR)))*T(i+1)==0;
[A,B] = equationsToMatrix([A(i,:)],[T(i,:)]);
end
X = linsolve(A,B)
This is currently what I have written, I'm trying to solve a system of equations where using information provided by the user, C,N,gamma, it will use the formula displayed by what A(i,:) is equal to to create a system of equations and will then solve for the values of T_0 to T_N. I was able to solve the system without the for loop but cannot seem to figure out how to do it with the for loop. I'm sure there are many mistakes in this code, I'm seeking any sort of guidance I can get. I'm stuck on an error with the symbols, "Undefined function 'T' for input arguments of type 'double' ". Any sort of help would be apprecitated greatly.
  16 件のコメント
darova
darova 2020 年 4 月 24 日
YOu mean B vector? Here it is
B1 = zeros(N+1,1);
B1(1) = 1;
And then solve for T as you did previously
T1 = A1\B1;
Ryan Mulligan
Ryan Mulligan 2020 年 4 月 24 日
Yes thank you so much, I was forgetting to add the first row of B as 1, that's where my error was. Thank you again.

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

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by