Finding error like unrecognized function or variable ' tridiagonal'

1 回表示 (過去 30 日間)
Aman Murkar
Aman Murkar 2021 年 10 月 2 日
編集済み: C B 2021 年 10 月 3 日
Program:
% solution of 2D elliptical solution
% using Line Over Relaxation Method(LSOR)
% ep is accepted error%Tridiag: Tridiagonal equation zsolver banded system
clc;
clear all;
eps = 0.001;
omega = input(' enter the omega value: ');
beta = input (' enter the beta value: ');
n= 10000;
nx = 21;
ny = 42;
T(1:nx, 1:ny-1) = 0;
TN(1:nx, 1:ny-1) = 0;
T(1:nx, ny)= 100;
TN(1:nx, ny) = 100;
% its number of iteration
coeff = ( 2*(1+beta^2));
for iterations = 1:n
for j = 2:ny-1
a(1:nx-2) = -coeff;
b(1:nx-3)= omega;
c(1:nx-3)= omega;
for i = 2:nx-1
r(i-1) = - coeff*(1-omega)*T(i,j)-omega*beta^2*T(i,j+1)-omega*beta^2*TN(i,j-1);
end
r(1)= r(1)-omega*TN(1,j);
r(nx-2)= r(nx-2)-omega*TN(nx,j);
y = tridiagonal(c,a,b,r);
for k = 1:nx-2
TN(k+1,j)= y(k);
end
end
error = abs(TN-T);
totalerror = sum(error,'all');
if totalerror <= eps
break
end
T=TN;
end
iterations;
contour(TN');
RESULTS;
enter the omega value: 1.3
enter the beta value: 1
Unrecognized function or variable 'tridiagonal'.
Error in LSOR (line 28)
y = tridiagonal(c,a,b,r);
  4 件のコメント
C B
C B 2021 年 10 月 2 日
@Aman Murkar your have defined function as Tridiagonal and calling it using tridiagonal
C B
C B 2021 年 10 月 2 日
Plus i have changed a part of code please check if its as per requirement or not
% b(1:nx-3)= omega;
% c(1:nx-3)= omega;
b(1:nx-2)= omega;
c(1:nx-2)= omega;

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

採用された回答

C B
C B 2021 年 10 月 2 日
編集済み: C B 2021 年 10 月 2 日
function main
% solution of 2D elliptical solution
% using Line Over Relaxation Method(LSOR)
% ep is accepted error%Tridiag: Tridiagonal equation zsolver banded system
clc;
clear all;
eps = 0.001;
omega = input(' enter the omega value: ');
beta = input (' enter the beta value: ');
n= 10000;
nx = 21;
ny = 42;
T(1:nx, 1:ny-1) = 0;
TN(1:nx, 1:ny-1) = 0;
T(1:nx, ny)= 100;
TN(1:nx, ny) = 100;
% its number of iteration
coeff = ( 2*(1+beta^2));
for iterations = 1:n
for j = 2:ny-1
a(1:nx-2) = -coeff;
% b(1:nx-3)= omega;
% c(1:nx-3)= omega;
b(1:nx-2)= omega;
c(1:nx-2)= omega;
for i = 2:nx-1
r(i-1) = - coeff*(1-omega)*T(i,j)-omega*beta^2*T(i,j+1)-omega*beta^2*TN(i,j-1);
end
r(1)= r(1)-omega*TN(1,j);
r(nx-2)= r(nx-2)-omega*TN(nx,j);
y = Tridiagonal(c,a,b,r);
for k = 1:nx-2
TN(k+1,j)= y(k);
end
end
error = abs(TN-T);
totalerror = sum(error,'all');
if totalerror <= eps
break
end
T=TN;
end
iterations;
contour(TN');
end
function x = Tridiagonal(e,f,g,r)
% Tridiagonal: Tridiagonal equation solver banded system
% x = Tridiagonal(e,f,g,r): Tridiagonal system solver.
% input:
% e = subdiagonal vector
% f = diagonal vector
% g = superdiagonal vector
% r = right hand side vector
% output:
% x = solution vector
n=length(f);
% forward elimination
for k = 2:n
factor = e(k)/f(k-1);
f(k) = f(k) - factor*g(k-1);
r(k) = r(k) - factor*r(k-1);
end
% back substitution
x(n) = r(n)/f(n);
for k = n-1:-1:1
x(k) = (r(k)-g(k)*x(k+1))/f(k);
end
end
  3 件のコメント
Aman Murkar
Aman Murkar 2021 年 10 月 2 日
thanks I got iterations too by doing some changes thanks for helping me.
Now the main part comes that can you tell me specifically what mistakes do i did as i am just learning matlab and how I can avoid such mistakes? Hope you will guide me.
Thanks again
C B
C B 2021 年 10 月 2 日
編集済み: C B 2021 年 10 月 3 日
@Aman Murkar your have defined function as Tridiagonal and calling it using tridiagonal

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by