Plotting a contour of a function with one input variable
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi
My function essentially has 2 inputs , x and y, but they're in the form theta = (x;y). So the first line of my code is x = theta(1,1), y = theta(2,1), and my function takes one input theta which should be a 2x1 matrix.
I need to plot a contour of the function with x and y taking certain values. But when I use "fcontour" I get 'not enough input arguments'. I'm not able to change the number of inputs for my function, it has to take a single input theta.
Any help would be appreciated for the contour plot! Thank you
0 comentarios
Respuestas (1)
Chris
el 2 de Nov. de 2021
Editada: Chris
el 2 de Nov. de 2021
exes = linspace(-2*pi,2*pi);
whys = exes;
theta = [exes',whys'];
takeOneInput(theta)
You can pack as much as you want into an input, depending on the data type. This one uses fcontour.
theta2.fun = @(x,y) sin(x) + cos(y);
theta2.xyinterval = [-2*pi,2*pi, -2*pi, 2*pi]
takeAnotherInput(theta2)
function takeOneInput(theta)
[x,y] = meshgrid(theta(:,1),theta(:,2));
f = sin(x) + cos(y);
contour(theta(:,1),theta(:,2),f);
end
function takeAnotherInput(theta)
fcontour(theta.fun,theta.xyinterval);
end
But if you are designing the function, why is it only permitted to take one input?
0 comentarios
Ver también
Categorías
Más información sobre Contour Plots 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!