Storing Iteration Results in Matlab

  • MATLAB
  • Thread starter adeeyo
  • Start date
  • Tags
    Matlab
In summary, the code is trying to calculate Z and V for all values of T(k), but is getting confused because the variables Z and V are being stored in a different way than the T(k) variable.
  • #1
adeeyo
20
0
Dear All,


Please help me on this little problem.

I have the code below.

for k=40:10:80
T(k)=273.15+k;
z=[0.2 0.2 0.2 0.4];
W_PR=0.245;
C=4;
omega=[0.344 0.467 0.578 0.789];
Tc=[600 700 500 570];
Pc=[50 70 58 76];
for c=1:C

x_PR(1,c)=z(c)/(1+W_PR*(K_PR(c)-1));
x_PR(2,c)=K_PR(c)*x_PR(1,c);
end
for c=1:C
kappa_PR=0.37464+1.54226.*omega(c)-0.26992.*omega(c).^2;
alpha_PR=(1+kappa_PR.*(1-sqrt(T(k)./Tc(c)))).^2;
a_PR(c,c)=0.45724.*R.^2.*Tc(c).^2./Pc(c).*alpha_PR;
b_PR(c)=0.07780*R.*Tc(c)./Pc(c);
end
for c=2:C
for n=1:(c-1)
a_PR(c,n)=sqrt(a_PR(c,c).*a_PR(n,n));
a_PR(n,c)=a_PR(c,n);
end
end
for c=1:C
A_PR(c,c)=a_PR(c,c).*P./(R.*T(k)).^2;
B_PR(c)=b_PR(c).*P./(R.*T(k));
end
for c=1:C
Z(c,c)=A_PR(c,c)./5;
V(c)=B_PR(c).*6;
end
end

QUESTION: Each time I run the code, I want result for Z and V at each T(k). The code as it is only gives result for one T value though I want it to run the loop and give result for Z and V for all T(k).

Thanks

adeeyo
 
Physics news on Phys.org
  • #2
[edited with apologies]
you have managed to make a vector for T, and store the kth value in the kth position in the vector.
So what is stopping you doing the same for Z and V.

You'd have to put Z and V inside the k loop - encoding Z(k,c,c) and V(k,c)
 
Last edited:
  • #3
Hi Simon,
I put Z and V inside k loop, but is giving me 80 by 4 by 4 matrix for Z instead of 5 by 4 by 4 matrix. Since my k=40:10:80; and T(k)=273.15+k;
Any advice?

Thanks
 
  • #4
Well yes - you will have to change how these things get calculated too.
Clearly you have missed a step or terminated the cycle too soon.
 
  • #5
Hi Simon,
I have checked the code over and over again I could not figure out where I got it wrong.
Please help me to check and verify the code.

Thanks
 
  • #6
flow-chart it.

you can hire me to do it...
 
  • #7
Please assist. I am a student.
 

Related to Storing Iteration Results in Matlab

What is the purpose of storing iteration results in Matlab?

Storing iteration results in Matlab allows for the preservation and analysis of data generated by iterative processes. This can help researchers track changes over time and make comparisons between different iterations.

How do I store iteration results in Matlab?

To store iteration results in Matlab, you can use the "for" or "while" loop functions to run your iterative process and save the results in a variable. You can also use the "save" function to export the results to a file for future use.

Can I access stored iteration results in Matlab at a later time?

Yes, stored iteration results in Matlab can be accessed at any time using the variable or file in which they were saved. This allows for continued analysis and comparison of data even after the iterative process has been completed.

What are some best practices for storing iteration results in Matlab?

Some best practices for storing iteration results in Matlab include using clear and descriptive variable names, saving results in a structured format, and documenting the purpose and conditions of the iterations for future reference.

Are there any limitations to storing iteration results in Matlab?

One limitation of storing iteration results in Matlab is that it can consume a significant amount of memory, especially if the results are large or numerous. It is important to consider memory limitations and optimize code for efficient storage of results.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
529
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
842
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
481
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top