1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: MATLAB question

  1. Apr 7, 2010 #1
    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!

    clear all
    close all

    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

    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. jcsd
  3. Apr 8, 2010 #2


    Staff: Mentor

    Which "above expression"? Which line is causing you problems, and what exactly are the problems?
  4. Apr 8, 2010 #3
    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook