How do I structure two for loops which do very different things?

1 view (last 30 days)
I am modeling a physics problem. I have an initial vector of values for each point in the domain. I want to use explicit Euler method to step in time to model the unsteady problem. How do i manifest the two for loops, one for the time procedure, and one for calling the elements of the vector#?
I have coded the numerical analysis model, however I have come undone at how to keep the loops separate whilst gaining the wanted outcome. I have tried numerous times to no success.
  2 Comments
James Tursa
James Tursa on 3 Feb 2016
Can you post a short example, even if it is just pseudo-code, to show what you have done?
Physics Guy
Physics Guy on 8 Feb 2016
Edited: Stephen23 on 8 Feb 2016
Below is a sample of my code. I have a time dependent problem.
r=[ ri : dr : rf ] ; % values of independent variable
% Boundary conditions in linear system
u(1)= ui;
u(2) = uii;
u(N) = uff;
u(N+1)= uf;
% Create finite difference array
for j = 3:N-1
A(j,j-2) = -1/(12*(dr^2))+1/(12*dr*r(j));
A(j,j-1) = 16/(12*(dr^2))-8/(12*dr*r(j));
A(j,j) = -30/(12*(dr^2))-1/((r(j))^2);
A(j,j+1) = 16/(12*(dr^2))+8/(12*dr*r(j));
A(j,j+2) = -1/(12*(dr^2))-1/(12*dr*r(j));
end
% Boundary Values
b(1) = u(1) ;
b(2) = u(2);
b(N) = u(N);
b(N+1) = u(N+1);
b(3:N-1) = 0;
I can solve this for u no problem.
However i want to invoke a time stepping procedure. I don't know how to structure the two loops.
I need one to implement the time stepping. I believe i need a second one to iterate each element of the array. ( Im unsure if this is right)
Any advice?

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!