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.

7 views (last 30 days)
I mean i don't know how to express f(x,y)= 0 , x=y=0 .

Accepted Answer

Dimitris Kalogiros
Dimitris Kalogiros on 20 Aug 2018
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 Comment
Walter Roberson
Walter Roberson on 20 Aug 2018
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.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 20 Aug 2018
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.

Community Treasure Hunt

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

Start Hunting!