import pymatbridge ip = get_ipython() pymatbridge.load_ipython_extension(ip) %%matlab path(path,'/Users/rjl/chebfun/chebfun_v4.2.2889/chebfun') %%matlab x = chebfun('x'); L = chebop(@(u) diff(u,2) + u) %%matlab uleft = 3.; uright = 4; L.lbc = uleft; L.rbc = uright; %%matlab L %%matlab f = 0*x %%matlab g = L\f plot(g,'r') title('The Chebfun solution') %%matlab A = [cos(-1) sin(-1); cos(1) sin(1)]; b = [uleft; uright]; c = A\b; u = c(1)*cos(x) + c(2)*sin(x); error = max(abs(u-g)) plot(u) title('The exact solution') %%matlab L = chebop(@(x,u) diff(u,2) - x.*u, [-30,30]); L.lbc = 1; L.rbc = 0; u = L\0; plot(u) u %%matlab N = chebop(0,6); N.op = @(theta) diff(theta,2) + sin(theta); %%matlab N.lbc = -pi/2; N.rbc = pi/2; theta = N\0 %%matlab plot(-cos(theta)), grid on, ylim([-1 1]) title('Nonlinear pendulum (21.5)','fontsize',20) xlabel('t','fontsize',20), ylabel('height -cos(\theta)','fontsize',20) %%matlab N.lbc = -pi/2; N.rbc = 5*pi/2; theta = N\0; plot(-cos(theta)), grid on, ylim([-1 1]) title('Nonlinear pendulum (21.5), another solution','fontsize',20) xlabel('t','fontsize',20), ylabel('height -cos(\theta)','fontsize',20) %%matlab plot(theta) %%matlab L = chebop(@(u) diff(u,2) + u,[0,2],@(u) u-3,@(u) diff(u)-1) %%matlab f = chebfun('exp(x)', [0,2]); u = L\f %%matlab plot(u) %%matlab uprime = diff(u); uprime(2) %%matlab residual = diff(uprime) + u - f; max_residual = max(abs(residual)) plot(residual)