guys please help me, i'm trying to solve a simple moving PDE equation in matlab.(adsbygoogle = window.adsbygoogle || []).push({});

The equation i'm trying to solve is

dq(x,t)/dt=-c*dq(x,t)/dx

with initial condition for example q(x,0)=exp(-(x-5)^2)

c is a constant. What i want to do is to first discritize the initial condition with interval dx then because i have to know the value of -c*dq/dx, i use fourier transform in matlab then i multiply it by -c*i*k after that i invert the fourier transform back so i get the value of -c*dq/dx at every point in my grid. Then i solve it with matlab ODE solver such ODE45 but result is still incorrect, i don't know where i might have gone wrong, here is my code

******the main code********

N=2^14;c0=0.5;

dx=0.01;x=[0:dx:(N-1)*dx];%defining the dx for x

tspan=linspace(0,20,100);%defining the time span for the solution

%defining the initial condition

q0=exp(-(x-5).^2);

dqx = diskx(q0,dx,N,c0);

%calculating the solution

ode=@(t,q) rhs(t,diskx(q0,dx,N,c0)*q);

options = odeset('RelTol',1e-5,'AbsTol',1e-6);

[t,q] = ode23(ode,tspan,q0);

%animating the result

for i=1:length(tspan)

h=plot(x,q(i,;axis([0 164 -10 11]);

name=['Simpangan q(x,t) saat t=',num2str(t(i))];

title(name);

pause(0.1)

set(h,'EraseMode','xor');

end

******function diskx********

function dxq = diskx(q0,dx,N,c0)

dk=2*pi/((N-1)*dx);

k=[-(N-1)/2*dk:dk:(N-1)/2*dk];

Q0=fft(q0);

Q0T=fftshift(Q0);

dQ0T=-c0*i*k.*Q0T;

dQ0=ifftshift(dQ0T);

dxq=real(ifft(dQ0));

******function rhs********

function dqdt = rhs(t,dqx,q)

dqdt = [dqx'];

please give me hint or correct me if i'm wrong, because i've checked and rechecked that the result suppose to be correct and yet i'm still not getting what i want which is just a moving function with the speed c. thx guys

**Physics Forums - The Fusion of Science and Community**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Help!, solving simple PDE with ODE45 or ODE23 solver in matlab

Loading...

Similar Threads - Help solving simple | Date |
---|---|

I Need a help in solving an equation (probably differentiation | Nov 20, 2017 |

A Help solving non-linear ODE analytically | Sep 8, 2016 |

Need help solving a differential equation | Feb 28, 2016 |

Need help solving second-order nonlinear differential eq | Feb 3, 2015 |

Need help solving simple Differential problem (help) | Jan 30, 2011 |

**Physics Forums - The Fusion of Science and Community**