Contouring specific number of data points
Mostra commenti meno recenti
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;
Risposte (1)
Walter Roberson
il 28 Ott 2013
0 voti
Hint: x(1:100)
Categorie
Scopri di più su Contour Plots in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!