Plot figure for f(y,z)=0

조회 수: 5 (최근 30일)
Behi
Behi 2022년 5월 27일
댓글: Walter Roberson 2022년 5월 28일
Hi, I have two functions f and g.
and ; I want to plot f-g=0 (or f=g) in a yz plane of 3D plot. I can solve it and write y as a function of z and then plot it; but I want to know how I can plot f-g=0 directly.

답변 (1개)

John D'Errico
John D'Errico 2022년 5월 27일
편집: John D'Errico 2022년 5월 27일
Simple enough. Define the two functions. Then subtract them, and plot using fimplicit.
f = @(z) 0.07*z.^2./(0.09 + z.^2);
g = @(y,z) 0.003 + 0.01*42./((y - z).^2 + 42);
fminusg = @(y,z) f(z) - g(y,z);
fimplicit(fminusg)
xlabel y
ylabel z
grid on
It can be a bit simpler if you want to use syms, because then you don't need to define f and g as explicit functions of the to variables.
syms y z
f = 0.07*z.^2./(0.09 + z.^2);
g = 0.003 + 0.01*42./((y - z).^2 + 42);
fminusg = f - g;
fimplicit(fminusg,[-20,20 -.15 .15])
xlabel y
ylabel z
grid on
You can choose a different domain for y and z (in the call to fimplicit) if you wish to expand it. You can see I did that in the second figure.
  댓글 수: 2
Behi
Behi 2022년 5월 28일
Many thanks for the answer. I have Matlab 2015 and fimplicit is not defined. Is there any other functions to use instead for this version of Matlab?
Walter Roberson
Walter Roberson 2022년 5월 28일
sol = solve(fminusg, z, 'maxdegree', 4);
Y = linspace(-20,20);
Z = double(subs(sol, Y)).';
plot(Y, Z)
Your version is old enough that you do not have symbolic fplot() either, which would have simplified the code.
The solution is the roots of a polynomial of degree 4.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by