1. Not finding help here? Sign up for a free 30min 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!

Tabulate data from the mathlab program

  1. Oct 14, 2013 #1
    I need to tabulate the data for u(x,t) vs x. Someone help me please :(
    this is the program.

    L = 1.;
    T = 1.;
    maxk = 2500;
    dt = T/maxk;
    n=50;
    dx = L/n;
    cond = 1/4;
    b = 2.*cond*dt/(dx*dx);
    for i= 1:n+1
    x(i) = (i-1)*dx;
    u(i,1) = sin(pi*x(i));
    end
    for k=1:maxk+1
    u(1,k) = 0.;
    u(n+1,k)=0.;
    time(k) = (k-1)*dt;
    end
    for k=1:maxk
    for i=2:n;
    u(i,k+1)=u(i,k)+0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
    end
    end
    figure (1)
    plot (x,u(:,1),'-',x,u(:,100),'-',x,u(:,300),'-',x,u(:,600),'-')
    title ('Temperature within the explicit method')
    xlabel ('X')
    ylabel ('Y')
    figure (2)
    mesh (x,time,u')
    title ('Temperature within the explicit method')
    xlabel ('X')
    ylabel ('Temperature')
     
  2. jcsd
  3. Oct 14, 2013 #2

    Mark44

    Staff: Mentor

    What do you mean? Do you need to print the data in a table? If so, how many columns? What should the table look like?

    BTW, this is not the section for HW problems. I am moving this post back to where your other one is.
     
  4. Oct 14, 2013 #3
    yes i want to print the data and put it inside the table. two colomn which represent the graph
     
  5. Oct 14, 2013 #4

    Mark44

    Staff: Mentor

  6. Oct 14, 2013 #5
    Im in total lost :( can you help me to modify my program so that it can create a table? :(
     
  7. Oct 14, 2013 #6

    Mark44

    Staff: Mentor

    Something like this. I don't know if this is exactly what you need, but it's probably close.
    Code (Text):

    formatSpec = "%4.2f \t %4.2f \n";
    for k=1:maxk
      for i=2:n;
        u(i,k+1)=u(i,k)+0.5*b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
        fprintf(formatSpec, x(i), u(i, k + 1))
      end
    end
     
     
  8. Oct 14, 2013 #7
    what is %4.2f \t %4.2f \n meant?
     
  9. Oct 14, 2013 #8

    Mark44

    Staff: Mentor

    %4.2f is a format specifier - print a number in a field of width 4, with 2 places to the right of the decimal point. If you have numbers that take up more space, change the 4 to something bigger. If you want more places to the right of the decimal, change the 2 to something bigger.

    \t is a tab character
    \n is a newline character.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Tabulate data from the mathlab program
  1. MathLab Question (Replies: 0)

Loading...