Filter löschen
Filter löschen

Problem with equation built with RANDN() function

1 Ansicht (letzte 30 Tage)
Kaiser Ahmed Bhuiyan
Kaiser Ahmed Bhuiyan am 17 Mär. 2020
Kommentiert: Walter Roberson am 17 Mär. 2020
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

Antworten (1)

Walter Roberson
Walter Roberson am 17 Mär. 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 Kommentare
Kaiser Ahmed Bhuiyan
Kaiser Ahmed Bhuiyan am 17 Mär. 2020
Do in need to write this code at begining ?
or put it in the for loop ?
Walter Roberson
Walter Roberson am 17 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by