- Watch the free, online MATLAB Onramp tutorial (maybe even just the first 30 minutes will be enough)
- Read even a little of the documentation for the rand function
asking about command in matlab
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
what this command mean in details
Energy = 0.17+rand(1,1)*(0.19-0.17)
thanks
0 comentarios
Respuestas (2)
the cyclist
el 28 de Dic. de 2022
Are you willing to spend some time learning MATLAB? You will fully understand that line of code if you
0 comentarios
John D'Errico
el 28 de Dic. de 2022
As much as I completely agree with @the cyclist, that you need to start to learn MATLAB, you also need to learn to take apart a line of code. That in itself is a skill you need to learn. And it applies to ANY programming language. You would start at the most basic element of the code, and then work out, based on the order of operations in the language you are using.
And in fact, if you just read the docs for rand, you will find that exact form of the expression discussed. (Not a command though.)
So first, start in the middle. What does rand(1,1) do?
help rand
READ THE DOCUMENTATION WHEN YOU DON'T UNDERSTAND SOEMTHING.
And then TRY IT OUT! For example:
rand(1,1)
Along the way, you would learn about what rand returns, a stream of uniformly distributed random numbers. How many such numbers does the call rand(1,1) produce? (Exactly 1 of them.)
But where do they live? What does a uniformly distributed random number mean? What interval does the distribution lie in? If you don't know, then go back up and read the help again. Hint: It talks about the open interval (0,1).
Now, what happens when you mutlply such a number that originally lives in the interval (0,1), by some constant? Now where does that product live? In this case, you multiplied by the constant (0.19 - 0.17), which is just 0.02. It would seem logical that the product lies in the still open interval (0,0.02).
Similarly, now add some constant to that number. Where does it live?
As I said, you take apart the expression that you don't understand, startgin at the inside, then working out, going by the order of operations. So we would have this sequence of operations we need to understand.
rand(1,1)
rand(1,1)*(0.19 - 0.17)
0.17 + rand(1,1)*(0.19 - 0.17)
Each of them changes the previous result in a specific way. But we should be able to understand what the final result does, from each of those steps. Finally, perhaps a histogram might help.
X = 0.17 + rand(1,1000000)*(0.19 - 0.17);
histogram(X,'norm','pdf')
Of course now you might ask what this last line of code does as written. And again, you learn that by simply reading the help.
0 comentarios
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!