Problem with equation built with RANDN() function
2 views (last 30 days)
Show older comments
Hi , I have a problem with below program which actually using "randn(); function to update the values by using a for loop.
the problem is that the second part of equation ("i mean the equation---> pm(i,1)=pm(i,1)-(pm(i,1)/.005)+(sig*0.005*randn()); " ) which contains the randn() , isn't producing any values , all values in pm matrix are same !! (which shouldn't be)
I am in the middle of a project and it needs to be solved very soon , a prompt answer will be of great help.
a=(2*10^-9)/2; %particle diameter
n=1; %time step counter
ttc=0;
f=(6*1.82*10^-5*a);
sig=sqrt(2*1.38*10^-23*300*.005/f);
pm=zeros(30,1);
pm(:,1)=-.005;
% while()
for i=1:30
pm(i,1)=pm(i,1)-(pm(i,1)/.005)+(sig*0.005*randn());
end
0 Comments
Answers (1)
Walter Roberson
on 17 Mar 2020
Give the command
format long g
and then look at your pm values again.
Your pm values are different, but they are the same to 4 decimal places and your default format short is only displaying 4 decimal places.
2 Comments
Walter Roberson
on 17 Mar 2020
You just need it once at the command line to prove to yourself that the pm values really are different. It does not affect the calculation in any way. It does not need to be present in your code at all, as long as you do not want to display the values.
If you do want to display the values, then you can use fprintf() or num2str() or compose() telling it exactly what output format you want.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!