%% Problem Set I: Problems 4(b) & 5(a)

clear all; close all

%
%% 4(b) Using Green's Theorem to compute an area
% We compute the area inside one arch of a cycloid by using Green's Theorem to convert the area integral into a line integral. The line integral we need to compute is: (-1/2)\int_C ydx+ xdy where C is the boundary of the arch traversed counterclockwise.

% On the base of the area in question, i.e., along the x-axis, both y and
% dy are zero, so we only need to evaluate along the arch. We'll draw the
% cycloid just for the record.
syms t; cycloid = [t - sin(t),1 - cos(t)];
cycloidplot=fplot(cycloid(1), cycloid(2), [0 2*pi])
axis equal
area=(1/2)*(int(-(1-cos(t))*(1 - cos(t)) + (t - sin(t))*sin(t), [2*pi, 0]))
fig = gcf;
fig.Color = 'none';
fig.InvertHardcopy='off';
print -depsc I04_05_01bb.eps

%
%% 5(a) Using Green's Theorem to convert a line integral into a double integral
% We are asked to compute the work done by a force field on a partlcle moving around an ellipse, which, of course, is a line integral computation. We use Green's Theorem to convert the line integral into a double integral, which we evaluate via Matlab.

clear all; close all
syms x y z real; F = [-y+5*x, 3*y + x];
G = curl([F,0], [x,y,z]); G(3)
% Therefore, by Green's Theorem, the line integral 
%       int_C (-y + 5x)dx + (3y + x)dy =
% two times the area of the ellipse x^2 + 9y^2 = 9, which is pi times the 
% product of the lengths of the two semi axes, i.e., 3 and 1. The value 
% of the line integral is therefore 6*pi. Let's verify that by having 
% Matab do the computation
syms u v real; 2*4*int(int(1, v, 0, sqrt(1-(u/3)^2)), u, 0, 3)