
f(x,y) = xy/(x²+y²) ,(x,y)≠(0,0), f(x,y)= 0 , x=y=0.How to draw a graphics by using Matlab.
조회 수: 6 (최근 30일)
이전 댓글 표시
I mean i don't know how to express f(x,y)= 0 , x=y=0 .
댓글 수: 0
채택된 답변
Dimitris Kalogiros
2018년 8월 20일
Provided that you have symbolic maths toolbox you can use the following code :
clear; clc;
syms x y
% define function
f(x,y)=piecewise(x==0 & y==0, 0 , x*y/(x^2+y^2) )
%plot function
fsurf(f(x,y));
xlabel('x'); ylabel('y'); zlabel('f(x,y)')
This is what you should expect:

댓글 수: 1
Walter Roberson
2018년 8월 20일
f(x,y)=piecewise(x==0 & y==0, 0 , x*y/(x^2+y^2) )
should be
f(x,y)=piecewise(x==0 & y==0, 0 , (x^2+y^2)/sin(x^2+y^2) )
to match the initial question.
Unfortunately the fsurf() for this is slow. It also goes to +/- infinity in a number of places because sin() goes to 0 in a number of places. Basically the fsurf() is unusable unless you restrict the bounds a fair bit.
추가 답변 (1개)
Walter Roberson
2018년 8월 20일
f = @(x,y) (x.^2 + y.^2) .* sin(1 ./ max( x.^2 + y.^2, realmin ))
This code is incorrect for the case that x^2 + y^2 is less than realmin.
In such a case, the formula requires taking sin(1/small_value) where 1/small_value is greater than realmax, which therefore becomes sin(inf) which is NaN -- that is, the formula requires that NaN be generated for that situation. But the code does not do that for x^2 + y^2 between eps(realmin) and realmin: instead it will take sin(1/realmin) which has a definite value of about -0.955607093583484
If you require that NaN be generated for that case, then some more work would have to be done -- and you would get a different situation if you were permitted to do the calculation using the Symbolic Toolbox.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numbers and Precision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!