Delete entries in an array that are no longer needed

조회 수: 1(최근 30일)
I'm performing an iterative calculation that runs through 100002 iterations. Imagine a nozzle with area1 for the inlet and area2 for the exit. The main goal here is to perform a differential analysis of the nozzle for each iteration to arrive at some final values. The variables that require iterations are area (A), circumference (C), velocity (U), temperature (T), density (rho), pressure (P), Mach number (M), total temperature (Tt), and total pressure (Pt). So I have 9 variables that are iterated 100002 times. The computation time is about 30 minutes. This is not acceptable as I need to run 6 more cases.
Question: Is there a way to save the ith and the (i-1) term, where the ith term is the term I am calculating at the present iteration and the (i-1) is the previous term?

채택된 답변

D 2011년 4월 11일
Instead of using an array, you could just use two variables for each of your current variables.
At the end of one iteration, new_var = ...
At the start of the next iteration: old_var = new_var, then re-calculate new_var.
Your i-1 term is stored in old_var, your ith term in new_var.
  댓글 수: 1
Harold 2011년 4월 11일
Thanks, I will have to try this

댓글을 달려면 로그인하십시오.

추가 답변(0개)


Find more on Computational Geometry 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!

Translated by