I want to generate the random numbers in the closed area (rectangle).
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Haseeb Hashim
el 11 de Abr. de 2022
Respondida: Walter Roberson
el 11 de Abr. de 2022
I want to generate the random numbers in the closed rectangular area as shown below
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/960110/image.jpeg)
after generating these I have to calculate the definite integral for the function line marked by red shaded area by the Monte Carlo method. Any tips regarding this
0 comentarios
Respuesta aceptada
Dyuman Joshi
el 11 de Abr. de 2022
If you mean in the range (0,4) and (0,25) -
%N = number of points you want, you can also run a for loop (upto you how you want to do)
r=rand(1,N); %generates a 1xN row of random numbers between 0 and 1
%you can also call rand twice for each number
r1=4*r; %0 to 4
r2=25*r; %0 to 25
0 comentarios
Más respuestas (1)
Walter Roberson
el 11 de Abr. de 2022
r = rand(N,2);
rand_ab = r(:,1) * (b-a) + a;
rand_cd = r(:,2) * (d-c) + c;
rand_coords = [rand_ab, rand_cd];
0 comentarios
Ver también
Categorías
Más información sobre Numerical Integration and Differentiation 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!