Contouring specific number of data points

13 views (last 30 days)
Kody
Kody on 28 Oct 2013
Answered: Walter Roberson on 28 Oct 2013
I am writing a piece of code to determine the maximum of a function by using random pseudo-numbers to produce x and y values and then plotting them using contour(). It asks me use random pseudo-numbers for 10000 iterations, but only use the first 100 iterations when using contour(). I am a little confused as to how to approach this. I have a feeling I am off-the-mark.
%Lab 3 Question 4
close all; clear; clc;
F = @ (x,y) sinc(sqrt(x.^2 + y.^2) / pi);
xl = -8; xu = 8; yl = -8; yu = 8;
it = 10000;
MaxZ = 0;
r = rand(10000,1);
x = zeros(10000,1);
y = zeros(10000,1);
z = zeros(10000,10000);
for i = 1:it
x(i,1) = xl + (xu - xl) * r(i,1);
y(i,1) = yl + (yu - yl) * r(i,1);
z(i) = F(x(i), y(i));
if z(i) > MaxZ;
MaxZ = z(i);
MaxX = x(i);
MaxY = y(i);
end
end
hold on;
for i = 1:100
contour(x(i), y(i), z(i));
end
hold off;

Answers (1)

Walter Roberson
Walter Roberson on 28 Oct 2013
Hint: x(1:100)

Categories

Find more on Contour Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!