Setting initial condition as an inverse function in ODE15s wont plot. Am I missing something?
Ältere Kommentare anzeigen
Messing around with the diffusion equation discretized to du(n)/dt=K(u(n+1)-2u(n)+u(n-1) and changing the value of K but when I try to set K= 1/u(n) a long error message occurs with: Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. Warning: Failure at t=0.000000e+00. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (7.905050e-323) at time t. Code Provided:
function [t,u]=discretized
tspan = [0 100];
n=100;
y0=zeros(n,1);
for i=1:n
y0(n/2)=1;
end
[t,u]=ode15s(@f,tspan,y0);
for i=1:length(t)
plot(u(i,:))
title('Discretization of Diffusion Equation');
xlabel('Cell');
ylabel('Concentration');
pause(1);
end
end
function dudt=f(t,y)
n=100;
dudt=zeros(n,1);
K=1./(y(1));
dudt(1)=K*(y(2)-y(1));
for i=2:n-1
K=1./(y(i));
dudt(i)=K*(y(i+1)-2*(y(i))+y(i-1));
end
dudt(n)=K*(y(n-1)-y(n));
end
Any ideas on what the problem is?
6 Kommentare
Torsten
am 26 Feb. 2018
Since y0=0 almost everywhere, you divide by 0 almost everywhere.
Best wishes
Torsten.
Philip Mitchell
am 26 Feb. 2018
Torsten
am 26 Feb. 2018
Yes, but in the calculation of K, you divide by the concentrations of the cells, and these are 0.
Philip Mitchell
am 26 Feb. 2018
Torsten
am 26 Feb. 2018
No. The initial concentration y0 can't be 0 if you set K=1/y.
Philip Mitchell
am 26 Feb. 2018
Antworten (0)
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!