Hello, I need some help with differential equation solving in MATLAB. i got the following equation: (f is a function of two variables: distance x and time t)
df(x,t)/dt = (x - f(x,t))/(f'(x,t)) - x
where f'(x,t) is the derivative of f in respect to x. i wrote the function as: (by multiplying both sides with df/dx)
(df/dt) * (df/dx) = x-f - x*(df/dx)
i am using the MATLAB pdepe function to solve the equation and i keep receiving the following error:
"Warning: Failure at t=3.221102e-001. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (8.881784e-016) at time t. > In ode15s at 747 In pdepe at 317 In solve at 11
Warning: Time integration has failed. Solution is available at requested time points up to t=3.201601e-001."
Can someone help me??
This is my code:
%% defining equation
function [c,f,s] = eqn1(x,t,u,DuDx) c=DuDx; f=-x*u; s=x; end
%% initial condition function value = initial1(x) value=0.5*(x^2); end
%% boundary conditions function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t) pl=ul; ql=0; pr=ur-1; qr=0; end
%PDE1: MATLAB script
%solutions to the PDE stored in eqn1.m
close all; clc; clear all; clc;
m=0;
options=odeset('NonNegative',[]);
%Define solution
x = linspace(0,1,100);
t = linspace(0,20,20*100);
%Solve the PDE
u = pdepe(m,@eqn1,@initial1,@bc1,x,t,options);
%Plot solution
surf(x,t,u);
title('Surface plot of solution.');
xlabel('Distance x');
ylabel('Time t');
No products are associated with this question.
function edp11
close all; clc;
m=0;
options=odeset('NonNegative',[]);
x = linspace(0,1,30);
t = linspace(0,20,30);
u = pdepe(m,@eqn1,@initial1,@bc1,x,t,options);
surf(x,t,u(:,:,1));
title('Surface plot of solution.');
xlabel('Distance x');
ylabel('Time t');
function [c,f,s] = eqn1(x,t,u,DuDx) c=DuDx; f=-x*u; s=x;
%% initial condition function value = initial1(x) value=0.5*(x^2);
%% boundary conditions function [pl,ql,pr,qr] = bc1(xl,ul,xr,ur,t) pl=ul; ql=0; pr=ur-1; qr=0;
I suggest you set a vector for tspan and experiment with it until you see what your function is doing and why it is crashing at that time. (The solver will evaluate the function at times other than those in the tspan vector. However, in my experience, you can use tspan to avoid such singularities if the vector elements aren't too close to them.)
Another possibility is to use the 'Events' option in odeset to do what you can to avoid what may be a singularity. It depends on how important the time in the region of 0.322 is to you.
Hello Star, Thank you for your reply.
Can you please explain more or give an example? Can you please explain more on " in my experience, you can use tspan to avoid such singularities if the vector elements aren't too close to them"
and How do i use 'events'?
I apologize if my questions seem stupid, but i am new to this field..
Best regards, Joe
I suggest replacing t in your pdepe call with something like tvct defined as:
tvct = 0 : 0.1 : 5;
or some such, depending on the times over which you want your functon to be integrated. That would produce time values for the function to integrate specifically at 0.3 and 0.4, avoiding the discontinuity or singularity in the region of 0.322. That strategy has worked for me in the past.
I've only used 'Events' once and not recently. I refer you to odeset for details. However depending on what you want to accomplish with your integration (for instance how important the time around 0.322 is in your application), it might be something to consider.
Be assured that your question is definitely not stupid.
0 Comments