Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

Symbolic Math Toolbox를 사용한 해석적 플로팅

Symbolic Math Toolbox™는 숫자 데이터를 명시적으로 생성하지 않고도 수학 표현식의 해석적 플로팅을 제공합니다. 이러한 플롯은 2차원 또는 3차원의 선, 곡선, 등고선, 곡면 또는 메시일 수 있습니다.

다음 예제에서는 기호 함수, 기호 표현식 및 기호 방정식을 입력값으로 받는 다음과 같은 그래픽스 함수를 사용합니다.

  • fplot

  • fimplicit

  • fcontour

  • fplot3

  • fsurf

  • fmesh

  • fimplicit3

fplot을 사용하여 양함수 y=f(x) 플로팅하기

함수 sin(exp(x))를 플로팅합니다.

syms x
fplot(sin(exp(x)))

Figure contains an axes object. The axes object contains an object of type functionline.

삼각 함수 sin(x), cos(x)tan(x)를 동시에 플로팅합니다.

fplot([sin(x),cos(x),tan(x)])

Figure contains an axes object. The axes object contains 3 objects of type functionline.

a의 여러 값에 대해 y=f(x,a)로 정의된 함수 플로팅하기

a=1,2, 4에 대해 함수 sin(exp(x/a))를 플로팅합니다.

syms x a
expr = sin(exp(x/a));
fplot(subs(expr,a,[1,2,4]))
legend show

Figure contains an axes object. The axes object contains 3 objects of type functionline.

함수의 도함수와 적분 플로팅하기

함수 f(x)=x(1+x)+2, 그 도함수 df(x)/dx 및 적분 f(x)dx를 플로팅합니다.

syms f(x)
f(x) = x*(1 + x) + 2
f(x) = xx+1+2
f_diff = diff(f(x),x)
f_diff = 2x+1
f_int = int(f(x),x)
f_int = 

x2x2+3x+126

fplot([f,f_diff,f_int])
legend({'$f(x)$','$df(x)/dx$','$\int f(x)dx$'},'Interpreter','latex','FontSize',12)

Figure contains an axes object. The axes object contains 3 objects of type functionline. These objects represent $f(x)$, $df(x)/dx$, $\int f(x)dx$.

a를 가로 축으로 하여 함수 y=g(x0,a) 플로팅하기

미분 방정식 dg(x,a)/dx=0을 풀어 함수 g(x,a)를 최소화하는 x0을 구합니다.

syms g(x,a);
assume(a>0);
g(x,a) = a*x*(a + x) + 2*sqrt(a)
g(x, a) = 2a+axa+x
x0 = solve(diff(g,x),x)
x0 = 

-a2

a가 0부터 5까지일 때 g(x0,a)의 최소값을 플로팅합니다.

fplot(g(x0,a),[0 5])
xlabel('a')
title('Minimum Value of $g(x_0,a)$ Depending on $a$','interpreter','latex')

Figure contains an axes object. The axes object with title Minimum Value of g leftParenthesis x indexOf 0 baseline , a rightParenthesis Depending on a, xlabel a contains an object of type functionline.

fimplicit를 사용하여 음함수 f(x,y)=c 플로팅하기

반지름 r이 1부터 10까지의 정수일 때 x2+y2=r2로 정의된 원을 플로팅합니다.

syms x y
r = 1:10;
fimplicit(x^2 + y^2 == r.^2,[-10 10])
axis square;

Figure contains an axes object. The axes object contains 10 objects of type implicitfunctionline.

fcontour를 사용하여 함수 f(x,y)의 등고선 플로팅하기

등고선 레벨이 –6부터 6까지일 때 함수 f(x,y)=x3-4x-y2의 등고선을 플로팅합니다.

syms x y f(x,y)
f(x,y) = x^3 - 4*x - y^2;
fcontour(f,[-3 3 -4 4],'LevelList',-6:6);
colorbar
title 'Contour of Some Elliptic Curves'

Figure contains an axes object. The axes object with title Contour of Some Elliptic Curves contains an object of type functioncontour.

스플라인 보간을 사용하여 해석 함수와 그 근삿값 플로팅하기

해석 함수 f(x)=xexp(-x)sin(5x)-2를 플로팅합니다.

syms f(x)
f(x) = x*exp(-x)*sin(5*x) -2;
fplot(f,[0,3])

해석 함수에서 몇 개의 데이터 점을 생성합니다.

xs = 0:1/3:3;
ys = double(subs(f,xs));

데이터 점과 해석 함수를 근사하는 스플라인 보간을 플로팅합니다.

hold on
plot(xs,ys,'*k','DisplayName','Data Points')
fplot(@(x) spline(xs,ys,x),[0 3],'DisplayName','Spline interpolant')
grid on
legend show
hold off

Figure contains an axes object. The axes object contains 3 objects of type functionline, line. One or more of the lines displays its values using only markers These objects represent Data Points, Spline interpolant.

함수의 테일러 근사 플로팅하기

x=0 근처에서 5차수 및 7차수까지 cos(x)의 테일러 전개를 구합니다.

syms x
t5 = taylor(cos(x),x,'Order',5)
t5 = 

x424-x22+1

t7 = taylor(cos(x),x,'Order',7)
t7 = 

-x6720+x424-x22+1

cos(x) 및 그 테일러 근사를 플로팅합니다.

fplot(cos(x))
hold on;
fplot([t5 t7],'--')
axis([-4 4 -1.5 1.5])
title('Taylor Series Approximations of cos(x) up to 5th and 7th Order')
legend show
hold off;

Figure contains an axes object. The axes object with title Taylor Series Approximations of cos(x) up to 5th and 7th Order contains 3 objects of type functionline.

구형파의 푸리에 급수 근사 플로팅하기

주기 2π 및 진폭 π/4인 구형파는 푸리에 급수 전개로 근사할 수 있습니다.

sin(t)+13sin(3t)+15sin(5t)+....

주기 2π 및 진폭 π/4인 구형파를 플로팅합니다.

syms t y(t)
y(t) = piecewise(0 < mod(t,2*pi) <= pi, pi/4, pi < mod(t,2*pi) <= 2*pi, -pi/4);
fplot(y)

구형파의 푸리에 급수 근사를 플로팅합니다.

hold on;
n = 6;
yFourier = cumsum(sin((1:2:2*n-1)*t)./(1:2:2*n-1));
fplot(yFourier,'LineWidth',1)
hold off

Figure contains an axes object. The axes object contains 7 objects of type functionline.

푸리에 급수 근사는 비약 불연속(jump discontinuity)에서 오버슈트되며 근사에 항을 더 많이 더해가도 "링잉 현상"이 사라지지 않습니다. 이 동작을 깁스 현상이라고도 합니다.

fplot3을 사용하여 파라미터 곡선 (x(t),y(t),z(t)) 플로팅하기

t가 –10부터 10까지일 때 (sin(t),cos(t),t/4)로 정의된 나선을 플로팅합니다.

syms t
fplot3(sin(t),cos(t),t/4,[-10 10],'LineWidth',2)
view([-45 45])

Figure contains an axes object. The axes object contains an object of type parameterizedfunctionline.

fsurf를 사용하여 z=f(x,y)로 정의된 곡면 플로팅하기

log(x)+exp(y)로 정의된 곡면을 플로팅합니다. (숫자 데이터를 생성하지 않은 채) fsurf를 사용하여 그리는 해석적 플로팅은 x=0 근처에서 곡선 영역과 점근적 영역을 보여줍니다.

syms x y
fsurf(log(x) + exp(y),[0 2 -1 3])
xlabel('x')

Figure contains an axes object. The axes object with xlabel x contains an object of type functionsurface.

fsurf를 사용하여 다변량 곡면 (x(u,v),y(u,v),z(u,v)) 플로팅하기

다음과 같이 정의한 다변량 곡면을 플로팅합니다.

x(u,v)=u

y(u,v)=f(u)sin(v)

z(u,v)=f(u)cos(v)

여기서, f(u)=exp(-u2/3)sin(u)+3/2입니다.

u의 플롯 구간을 –5~5로 설정하고 v의 플롯 구간을 0~2π로 설정합니다.

syms f(u) x(u,v) y(u,v) z(u,v)
f(u) = sin(u)*exp(-u^2/3)+1.5;
x(u,v) = u;
y(u,v) = f(u)*sin(v);
z(u,v) = f(u)*cos(v);
fsurf(x,y,z,[-5 5 0 2*pi])

Figure contains an axes object. The axes object contains an object of type parameterizedfunctionsurface.

fmesh를 사용하여 다변량 곡면 (x(s,t),y(s,t),z(s,t)) 플로팅하기

다음과 같이 정의한 다변량 곡면을 플로팅합니다.

x=rcos(s)sin(t)

y=rsin(s)sin(t)

z=rcos(t)

여기서, r=8+sin(7s+5t)입니다. fmesh를 사용하여 플로팅된 곡면을 메시로 표시합니다. s의 플롯 구간을 0~2π로 설정하고 t의 플롯 구간을 0~π로 설정합니다.

syms s t
r = 8 + sin(7*s + 5*t);
x = r*cos(s)*sin(t);
y = r*sin(s)*sin(t);
z = r*cos(t);
fmesh(x,y,z,[0 2*pi 0 pi],'Linewidth',2)
axis equal

Figure contains an axes object. The axes object contains an object of type parameterizedfunctionsurface.

fimplicit3을 사용하여 음함수 곡면 f(x,y,z)=c 플로팅하기

음함수 곡면 1/x2-1/y2+1/z2=0을 플로팅합니다.

syms x y z
f = 1/x^2 - 1/y^2 + 1/z^2;
fimplicit3(f)

Figure contains an axes object. The axes object contains an object of type implicitfunctionsurface.

곡면의 등고선과 기울기 플로팅하기

fsurf를 사용하여 곡면 sin(x)+sin(y)-(x2+y2)/20을 플로팅합니다. 'ShowContours''on'으로 설정하면 동일한 그래프에 등고선을 표시할 수 있습니다.

syms x y
f = sin(x)+sin(y)-(x^2+y^2)/20
f = 

sin(x)+sin(y)-x220-y220

fsurf(f,'ShowContours','on')
view(-19,56)

Figure contains an axes object. The axes object contains an object of type functionsurface.

다음으로, 더 세밀한 등고선을 사용하여 별도의 그래프에 등고선을 플로팅합니다.

fcontour(f,[-5 5 -5 5],'LevelStep',0.1,'Fill','on')
colorbar

곡면의 기울기를 구합니다. meshgrid를 사용하여 2차원 그리드를 만들고 그리드 좌표를 대입하여 기울기를 수치적으로 계산합니다. quiver를 사용하여 기울기를 표시합니다.

hold on
Fgrad = gradient(f,[x,y])
Fgrad = 

(cos(x)-x10cos(y)-y10)

[xgrid,ygrid] = meshgrid(-5:5,-5:5);
Fx = subs(Fgrad(1),{x,y},{xgrid,ygrid});
Fy = subs(Fgrad(2),{x,y},{xgrid,ygrid});
quiver(xgrid,ygrid,Fx,Fy,'k')
hold off

Figure contains an axes object. The axes object contains 2 objects of type functioncontour, quiver.

참고 항목

함수