[英]Plotting a 2-variable implicit function in MatLab WITHOUT fimplicit or ezplot
我的任務是繪制隱式函數x ^ 2 + y ^ 2 = 1 + 4.5sin ^ 2(xy),並且不允許使用諸如fimplicit或ezplot之類的“隱式繪制函數”。
我被plot,polarplot和fzero卡住了,就是這樣。
這些說明似乎暗示着轉換為極性函數是關鍵,但是經過幾個小時的嘗試,閱讀和谷歌搜索之后,我仍然不知道該怎么做。
將x和y轉換為其極性形式仍然不能解決所有theta值的r問題,所以我很困惑。
任何幫助將不勝感激。
干杯!
由於不能同時使用輪廓線,彎曲線或ezplot。
我知道您的老師希望您使用implicit function theorem
。 您可以找到它的定義隱函數定理 。
我認為您應該從Wikipedia文章中的The circle example
開始。
請記住,您只需要為圖的一部分解決此問題,其余只是對稱性。
您的起點應該是(x = 0,y = 1),這是一個解決方案。
然后你會發現
dy/dx = (2x+9ysin(xy)cos(xy))/(2y+9xsin(xy)cos(xy))
您認識一個簡單的ODE
最簡單的解決方法是從(x = 0,y = 1)開始(這是一個解決方案),選擇一個dx步驟(0.01),然后保存算法中的所有點
y <- y + (2x+9ysin(xy)cos(xy))/(2y+9xsin(xy)cos(xy))*dx
x <- x + dx
直到遇到麻煩(雅各布式的決定因素為0)
對於提示,我離開劇情:
我相信當x在[-3,3]中並且對於y時,您的隱式函數都將給出結果。
所以
[x,y]=meshgrid([-3:0.01:3],[-3:0.01:3])
z= x.^2 + y.^2 - 1.0 - 4.5.*sin(x.*y).^2
v = [0,0];
contour(x,y,z,v)
應該給你像
theta = linspace(0, 2.*pi, 1000);
for i = 1:length(theta) % Want to check every angle in theta.
% asign x = r*cos(theta) and y = r*sin(theta. You want to set the equation
% equal to 0.
f = @(r)1 + 4.5.*(sin(r.^2.*(cos(theta(i)) .*sin(theta(i))))).^2 - r.^2;
r(i) = fzero(f, 3); % Solves the equation. The value 3 is just an
% approximation of r, set it to any number you like. It just can't be too high.
% Make the two coordinates x and y. Asign them to their polar coordinates
% using r.
x(i) = r(i).*cos(theta(i));
y(i) = r(i).*sin(theta(i));
end
plot(x,y)
grid on
axis equal
axis([-4 4 -4 4])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.