Trying to make my Implicit Function Work

조회 수: 6 (최근 30일)
Rheanne Perry
Rheanne Perry 2020년 11월 3일
댓글: Rheanne Perry 2020년 11월 3일
I'm trying to plot an implicit function but it keeps returning that it behaves unexpectedly on array inputs. I don't know that I'm doing wrong because my Parts all all vectors as well as my plotting variables.
%All known or base variables%
Xc = [];
Yc = [];
e = 5.194469088;
f = 5.193588373;
a1 = 5.2548;
a4 = 0.2271;
fi2 = 1.046746555;
%All substitute value variables%
P1 = 2 * Xc * f;
P2 = e * cos(fi2);
Q1 = 2 * Yc * f;
Q2 = -e * sin(fi2);
R1 = Xc.^2 + Yc.^2 + f^2 - a1^2;
R2 = Xc -a4;
%Equation Parts%
Part1 = (R1 * Q2) - (R2 * Q1);
Part2 = (P1 * R2) - (P2 * R1);
Part3 = (P1 * Q2) - (P2 * Q1);
%Equation and Plot%
eq = @(Xc,Yc) (Part1.^2 + Part2.^2 - Part3.^2);
figure;
fimplicit (eq,[-100 100 -100 100]);

채택된 답변

Steven Lord
Steven Lord 2020년 11월 3일
I'm going to walk through your code and comment on a few things along the way.
%All known or base variables%
Xc = [];
Yc = [];
e = 5.194469088;
f = 5.193588373;
a1 = 5.2548;
a4 = 0.2271;
fi2 = 1.046746555;
%All substitute value variables%
P1 = 2 * Xc * f;
Because Xc is empty so is P1. P1 is not a function of Xc or anything like that. If it were a function of Xc it would be something like:
P1 = @(Xc) 2*Xc*f;
Continuing on with your code:
P2 = e * cos(fi2);
Q1 = 2 * Yc * f;
Q1 is empty for the same reason P1 is except for Yc instead of Xc.
Q2 = -e * sin(fi2);
R1 = Xc.^2 + Yc.^2 + f^2 - a1^2;
R2 = Xc -a4;
R1 and R2 are empty because they're also functions of the empty matrix Xc. An empty plus or minus a scalar is still empty by scalar "expansion".
%Equation Parts%
Part1 = (R1 * Q2) - (R2 * Q1);
Part2 = (P1 * R2) - (P2 * R1);
Part3 = (P1 * Q2) - (P2 * Q1);
Each of these three parts is also empty.
%Equation and Plot%
eq = @(Xc,Yc) (Part1.^2 + Part2.^2 - Part3.^2);
So your "function of Xc and Yc" actually doesn't depend on the inputs Xc and Yc at all. It returns the sum and difference of three empty matrices, which means a simpler way of writing eq is:
eq = @(~, ~) [];
So when you call fimplicit:
figure;
fimplicit (eq,[-100 100 -100 100]);
It passes in something nonempty and receives an empty back. That's why it issues the warning.
You probably want to make Part1, Part2, and Part3 functions of Xc and Yc, which will require making the P#, Q#, and R# lines into functions like I did with P1 (and calling them as functions rather than referring to them as variables.)
  댓글 수: 3
Steven Lord
Steven Lord 2020년 11월 3일
Part2 = @(Xc,Yc) ((P1 * R2) - (P2 * R1))^2;
This tries multiplying function handles P1 and R2. You can't do that. What you can do is multiply the results of evaluating function handles. [You're going to want to use element-wise multiplication rather than matrix multiplication.]
f1 = @(x) 2*x;
f2 = @(y) y.^3;
g = @(x, y) f1(x).*f2(y);
value = g(1:5, 6:10)
Model your eq, Part1, Part2, and Part3 functions after my g function.
Rheanne Perry
Rheanne Perry 2020년 11월 3일
Thank you so much, it works perfectly now.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by