Finite difference method problem with solving an equation

조회 수: 5 (최근 30일)
Aldo
Aldo 2016년 11월 8일
댓글: Torsten 2016년 11월 10일
Trying to use Finite difference method, to write the equation in AT = b matrices. But I don't know how to write FDM on that type of equation, please see image.

채택된 답변

Torsten
Torsten 2016년 11월 8일
(k(x_(i+1/2))*(T(x_(i+1))-T(x_(i)))/(x_(i+1)-x_(i))-k(x_(i-1/2))*(T(x_(i))-T(x_(i-1)))/(x_(i)-x_(i-1)))/(x_(i+1/2)-x_(i-1/2)) = Q(x_i)
with
x_(i+1/2)=(x_(i+1)+x_(i))/2
x_(i-1/2)=(x_(i)+x_(i-1))/2
Best wishes
Torsten.

추가 답변 (5개)

Torsten
Torsten 2016년 11월 8일
[d/dx(k*dT/dx)](x) ~ (k(x+h/2)*(dT/dx)(x+h/2) - k(x-h/2)*(dT/dx)(x-h/2))/h
Approximations for (dT/dx)(x+h/2) and dT/dx(x-h/2) are
(dT/dx)(x+h/2) ~ (T(x+h)-T(x))/h
(dT/dx)(x-h/2) ~ (T(x)-T(x-h))/h
Now insert in the first equation.
The finite-difference approximation in my first response was more general because it took into account non-equidistant grids (i.e. h is not fixed over the complete interval). But note that I missed the minus-sign in front of the approximaton for d/dx(k*dT/dx).
Best wishes
Torsten.

Torsten
Torsten 2016년 11월 9일
-(k(x_(i+1/2))*y_(i+1)-(k(x_(i+1/2))+k(x_(i-1/2)))*y_(i)+k(x_(i-1/2))*y_(i-1))/h^2 = Q(x_(i))
with
x_(i+1/2)=(x_(i)+x_(i+1))/2
x_(i-1/2)=(x_(i-1)+x_(i))/2
for i=2,...,(n-1)
y(1) and y(n) are given by your boundary conditions.
So to incorporate the boundary conditions, you can add the equations
y(1) = 300
y(n) = 410
to the system from above.
The complete system to be solved then looks like
y(1) = 300
-(k(x_(i+1/2))*y_(i+1)-(k(x_(i+1/2))+k(x_(i-1/2)))*y_(i)+k(x_(i-1/2))*y_(i-1))/h^2 = Q(x_(i)) (i=2,...,n-1)
y(n) = 410
Best wishes
Torsten.

Aldo
Aldo 2016년 11월 8일
Aren't you suppose to use this? Where did you get x_(i+1/2)=(x_(i+1)+x_(i))/2 x_(i-1/2)=(x_(i)+x_(i-1))/2 from?
Best regards Aldo :D

Aldo
Aldo 2016년 11월 8일
Can't figure out a way to get the equation to look like this. And shouldn't (dT/dx)(x+h/2) ~ (T(x+h)-T(x))/h, be divided by 2h?
Best regards

Aldo
Aldo 2016년 11월 9일
clear all; close all, clf;
T0=300; Tslut=410;
N=100;
h=410/N; n=N-1; x=h*(0:n)'; X=[0;x;410];
k=2+x/7; Q=260*exp(-(x-410/2).^2);
A= sparse(n);
for i=1:n-1, A(i,i)=(2*k/h^2); end
for i=1:n-1, A(i,i+1)= (k/h^2); A(i+1,i)= (k/h^2);end
b= Q
(1)= b(1)+(k/h^2)*T0
b(n)= b(n)+(k/h^2)*Tslut
T= A/b
I get this error "Subscripted assignment dimension mismatch. Error in uppgift5 (line 9) for i=1:n-1, A(i,i)=(2*k/h^2); end "
can you see how I can resolve it?
  댓글 수: 5
Aldo
Aldo 2016년 11월 10일
편집: Aldo 2016년 11월 10일
Yes you are right it doesn't take much time to calculate. However, how do you get T specifically at x=1.5? I am interested in finding the value of T at point 1.5
Best Regards Aldo :D
Torsten
Torsten 2016년 11월 10일
Take N=340 - then T at 1.5 is T(151) :-)
For arbitrary N,
T15 = interp1(x,T,1.5);
Best wishes
Torsten.

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

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by