How to evaluate a point in a solved differential equation in matlab?
Show older comments
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)
Torsten
on 13 Nov 2018
1 vote
y16 = interp1(xx,yy,1.6)
5 Comments
Maria Karlsson Osipova
on 13 Nov 2018
Bruno Luong
on 14 Nov 2018
"I need to do error analysis on the given value."
What kind of error analysis?
Torsten
on 14 Nov 2018
Most probably how abs(y_num-y_exact) at x=1.6 behaves as h->0.
Bruno Luong
on 14 Nov 2018
Edited: Bruno Luong
on 14 Nov 2018
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.
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!