Happy valentine's day 2025 with Nelson #1344
Nelson-numerical-software
started this conversation in
General
Replies: 1 comment
-
% Parameters
num_points = 100000; % Number of random points
% Generate random points in the bounding box [-1.5, 1.5] x [-1.5, 1.5]
x = -1.5 + 3 * rand(num_points, 1); % X-coordinates
y = -1.5 + 3 * rand(num_points, 1); % Y-coordinates
% Heart function: (x^2 + y^2 - 1)^3 - x^2*y^3 <= 0
inside_heart = (x.^2 + y.^2 - 1).^3 - x.^2 .* y.^3 <= 0;
% Plot the points
figure;
hold on;
scatter(x(inside_heart), y(inside_heart), 1, 'red', 'filled'); % Points inside the heart
scatter(x(~inside_heart), y(~inside_heart), 1, 'cyan'); % Points outside the heart
axis equal;
xlim([-1.5, 1.5]);
ylim([-1.5, 1.5]);
title('Monte Carlo Heart');
xlabel('x');
ylabel('y');
hold off; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions