How to write to make a computation grid with random numbers?
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Max Rayne
el 3 de En. de 2019
I have a grid where -9 ≤x≤9, -8≤y≤8, step size of 0.2.
In order to find all the local minima contained within this computational grid, for a given function, I want to run 150 Gradient Descent searches (for which I have written a function already) using randomised starting points
I know I need to use rand to populate x and y with valuesbetween 0 and 1,but I don't know how to do this and scale up these values to the limits of the numerical grid -9 ≤x≤9, -8≤y≤8, step size of 0.2.
Would anyone be able to explain how i can make this grid?
Thanks in advance!
0 comentarios
Respuesta aceptada
Stephan
el 3 de En. de 2019
Editada: Stephan
el 3 de En. de 2019
Hi,
if your function that uses the randomized values is vectorized, you can use this code:
x = -9:0.2:9;
y = -8:0.2:8;
id_x = randi(numel(x),150,1);
id_y = randi(numel(y),150,1);
values = [x(id_x); y(id_y)]';
This produces a 150x2 matrix containing random pairs of x values between -9:0.2:9 in the first column and y values between -8:0.2:8 in column 2.
If you did not vectorize your function you can loop through this matrix to perform your calculations.
Best regards
Stephan
0 comentarios
Más respuestas (0)
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!