# Homework Help: MATLAB question

1. Apr 7, 2010

### Cornelius

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.
1. The problem statement, all variables and given/known data

2. Relevant equations

3. The attempt at a solution

2. Apr 8, 2010

### Staff: Mentor

Which "above expression"? Which line is causing you problems, and what exactly are the problems?

3. Apr 8, 2010

### Cornelius

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 occuring 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.