How to evaluate a point in a solved differential equation in matlab?

Hello!
I have a problem with  solving a DE with my matlab code, or more specifically I don't know how to continue solve a problem.
The question is to solve this equation and evaluate T at x=1.6.
The dif.equation is as follows:
% -d(k*dT/dx)/dx=Q(x)
% where k=2+x/7 ; Q=260*e^-(x-L/2)^2 ; where 0<=x<=L
I have solved it with finite difference methd, and it seems to work. How do I evaluate T at x=1.6? from here?
Here is what I got so far in the code:
%Given values:
x0=0;
xn=3.6;
y0=320;
yn=450;
L=3.6;
n=40;
h=(xn-x0)/n;
x=x0+h*[1:n-1];
Q = @(x) 260.*exp(-(x-L/2).^2);
alfa= @(x) 1/(14*h)-2/(h^2)-x./(7*h^2);
beta= @(x) 4/h^2+((2/(7*h^2)).*x);
gamma= @(x) -1/(14*h)-x./(7*h^2)-(2/h^2);
A1=diag(alfa(x(2:n-1)),-1);
A2=diag(beta(x));
A3=diag(gamma(x(1:(n-2))),1);
A=A1+A2+A3;
b=Q(x);
b(1)= b(1)-alfa(x0)*y0;
b(n-1)=b(n-1)-gamma(xn)*yn;
y=A\b';
xx=[x0 x xn]
yy=[y0 y' yn]
plot(xx,yy)
xlabel('Length'); ylabel('Temperature')

Answers (1)

y16 = interp1(xx,yy,1.6)

5 Comments

Thank you! However, I forgot to mention that I need to do error analysis on the given value.
Ok. In order to prevent interpolation errors, include x=1.6 in your discretization (i.e. 1.6 should be part of
x=x0+h*[1:n-1];
).
E.g. if n=36*i, y(16*i) gives T at x=1.6 where "i" can be chosen as 1,2,3,4,...
Best wishes
Torsten.
"I need to do error analysis on the given value."
What kind of error analysis?
Most probably how abs(y_num-y_exact) at x=1.6 behaves as h->0.
I'm not aware if such local error estimate exists, do you?
There is a lot of formula to estimate residual error in some global Banach's/Hilbert norm
|y-y_h| <= C*h^alpha |y_h|.
Not sure how such local norm |y-y_h|(x=1.6) would need as input to get an error bound.
That's why my question.

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Release

R2017b

Edited:

on 14 Nov 2018

Community Treasure Hunt

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

Start Hunting!