×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Vectorize --- C -> Matlab / Heat equation

Vectorize --- C -> Matlab / Heat equation

Vectorize --- C -> Matlab / Heat equation

(OP)
I want to 'translate' some programs I had in C for matlab but by sigtly optimizing the code for matlab use. I am new in matlab. So, I had the following code:

(1) for K = 1:dT:M

    (2) for I = 1:dX:N+1
        dU(I) = (U(I+1)-2*U(I)+U(I-1))/dX^2;
        end

    (3) for I = 1:dX:N+1
        U(I) = U(I)+dU(I)*dT
        end

     end

This actually is a simple implementation of an explicit scheme for the numerical solution of the heat equation. Now I managed to do this and eliminate the (2) and (3) loop:

(1) for K = 1:dT:M

(2) dU(1:N+1) = (U([2:end 1])-2*U+U([end 1:end-1]))/dX^2;
U(I+1)-->U([2:end 1])
U(I-1)-->U([end 1:end-1])

(3) U(1:N+1) = U(1:N+1)+dU(1:N+1)*dT

     end

I could really use your help in order to eliminate the (1) time loop, in a way that the values of U(1:N+1) are stored for each time step dT or, in case M is very large this would take a lot of memory and time, get 'snapshots' every a couple of timesteps which I could define explicitly.




Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources