Plotting a contour of a function with one input variable
2 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Chris
2021 年 11 月 2 日
編集済み: Chris
2021 年 11 月 2 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!