Controlling peak position and extracting final value in MATLAB PDE simulation

  • Thread starter Thread starter Cornelius
  • Start date Start date
  • Tags Tags
    Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
Cornelius
Messages
4
Reaction score
0
1. In the below code, I need to know how to ensure that the peaks end up near the middle. I also want to know how to calculate the end value of "u". Thanks!



2.
clear all
close all
clc

u = 1000*ones(1,200);
dt = 0.01;
dx = 1/201;
for i = 2:10/dt
dudt = diff(u(i-1,:));
Du = 10*log(10*exp(-0.0001*u(i-1,:)));
dudt = diff(Du(1:end-1).*dudt);
u(i,:)= u(i-1,:);
u(i,2:end-1) = u(i,2:end-1)+dudt*dt;
u(i,1) = u(i,2)-10*(log(10*exp(-0.0001*u(i,1))))*(1-(log(10*exp(-0.0001*u(i,1))))/100)*dx;
u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end))))*(1-(log(10*exp(-0.0001*u(i,end))))/100)*dx;

hold on
plot(u(i,:))
end




3. I tried using "end/2" in the above expression, but it doesn't give me a suitable solution.
 
Physics news on Phys.org
Cornelius said:
1. In the below code, I need to know how to ensure that the peaks end up near the middle. I also want to know how to calculate the end value of "u". Thanks!



2.
clear all
close all
clc

u = 1000*ones(1,200);
dt = 0.01;
dx = 1/201;
for i = 2:10/dt
dudt = diff(u(i-1,:));
Du = 10*log(10*exp(-0.0001*u(i-1,:)));
dudt = diff(Du(1:end-1).*dudt);
u(i,:)= u(i-1,:);
u(i,2:end-1) = u(i,2:end-1)+dudt*dt;
u(i,1) = u(i,2)-10*(log(10*exp(-0.0001*u(i,1))))*(1-(log(10*exp(-0.0001*u(i,1))))/100)*dx;
u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end))))*(1-(log(10*exp(-0.0001*u(i,end))))/100)*dx;

hold on
plot(u(i,:))
end



3. I tried using "end/2" in the above expression, but it doesn't give me a suitable solution.

Which "above expression"? Which line is causing you problems, and what exactly are the problems?
 
u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end))))*(1-(log(10*exp(-0.0001*u(i,end))))/100)*dx;

that is the line that is giving me problems. Basically, when I run this simulation I get peaks occurring at the boundaries - instead, I want peaks to occur in the centre. Can I do this by the following code?

u(i,end) = u(i,end-1)+10*(log(10*exp(-0.0001*u(i,end/2))))*(1-(log(10*exp(-0.0001*u(i,end/2))))/100)*dx;

?

Also, if I wanted to compute the value of u at a particular place, how would I do that? Thanks a lot.