Finite Difference Method Boundary Value Problem

조회 수: 5 (최근 30일)
Lingbai Ren
Lingbai Ren 2021년 11월 10일
댓글: Jan 2021년 11월 11일
Hi, I am lost in this Boundary Value Problem requiring to use Finite Difference Method:
I attached what I have done and the hint our professor provided, I also tried different methods from other matlab questions and youtube, but it always runs some error.
Below this is the code I hae so far, it works but it does not look correct, can anyone help please? I will really appreciate that!
%% Initialize parameters
clc,clear
T_B = 600; % boundary condition
T_E = 350; % boundary condition
T_Inf = 300;
M = 4;
L = 2.0;
% Discretization
num_nodes = 51;
num_segments = num_nodes-1;
h = L/num_segments;
% x = T_B:-h:T_E;
xj = 0:h:L;
Q=@(T)(-4*(300-T));
% Building up matrix
diagonal = [1/h; 2/h^2*ones(num_segments-1,1); 1/h];
A = diag( diagonal);
for i = 2:num_segments+1
A(i-1,i)=-1/h^2; A(i,i-1)=-1/h^2; %%%%%%%%%%%%%% signs
end
A(1,2)=0; A(num_segments+1,num_segments)=0;
b = [T_B/h; Q(xj(2:end-1))'; T_E/h]; %%%%%%%%%%%%%%% Q(xj(2_end-1))' not just Q
T=A\b;
plot(xj,T),grid
  댓글 수: 3
Lingbai Ren
Lingbai Ren 2021년 11월 10일
Sorry, this is the plot I get
Jan
Jan 2021년 11월 11일
This does not clarify, wh yozu assume, that there is a problem. Remember, that the readers are not working in your field. So explain the problem like you would explain it to a rubber duck.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by