You are on page 1of 5

%Edgar Figueroa 17

March 2017
%MAE 305 Sec 02
%Project 2
clc; clear al;

%1 (section 4.7)
f1=inline('x^2+y^2-1.2','x','y');
f2=inline('2*x^2+3*y^2-3','x','y');
ezplot(f1)
hold on
ezplot(f2)

A11=inline('2*x','x','y');
A12=inline('2*y','x','y');
A21=inline('4*x','x','y');
A22=inline('6*y','x','y');

tol=1e-4; kmax=10; %sets tolerence and max


itterations
v(:,1)=[0.25;1];
%checks to see if root is found
%while two succesive vectors do not satify
terminating condition
%to the nature of functions near the root
for k=1:kmax,
A=[A11(v(1,k),v(2,k)) A12(v(1,k),v(2,k));
A21(v(1,k),v(2,k)) A22(v(1,k),v(2,k))];
b=[-f1(v(1,k),v(2,k));-f2(v(1,k),v(2,k))];

if abs(b(1))<tol && abs(b(2))<tol,


root=v(:,k)
return
end

delv=A\b;
v(:,k+1)=v(:,k)+delv %updated solution
if norm(v(:,k+1)-v(:,k))<tol,
%checks terminating condition
root=v(:,k+1)
break
end
end

v =

0.2500 1.3250 0.8889 0.7819 0.7746 0.7746


1.0000 0.8000 0.7750 0.7746 0.7746 0.7746

root =

0.7746
0.7746

>>

%2
clc; clear all;
x=[1 1.6 2 2.5 3 3.4 4 4.6 5 5.8];
y=[3.2 3.5 3.6 3.9 4.1 4.5 4.6 4.7 4.9 5.1];
plot(x,y,'o')
xx=log10(x); yy=log10(y);
[a1 a0]=LinearRegression(xx,yy)
xlabel('x')
ylabel('y')
title('linear fit of converted data')

a1 =

0.2806

a0 =

0.4894

>>
%3
clc; clear all;
%2nd Degree
x=[0:1:5];
y=[3.4 4.9 6.2 7.3 9.2 10.2];
P1=polyfit(x,y,2) %coefficients of 2n degree
polynomial fit
xi=linspace(0,5);
yi=polyval(P1,xi);
figure
subplot(2,1,1)
plot(xi,yi)
hold on
plot(x,y,'o')
title('2nd Degree Poly Fit')
xlabel('x')
ylabel('y')

%3rd Degree
P2=polyfit(x,y,5)
yii=polyval(P2,xi);
subplot(2,1,2)
hold on
plot(xi,yii)
plot(x,y,'o')
title('5th Degree Poly Fit')
xlabel('x')
ylabel('y')

P1 =

-0.0018 1.3804 3.4321

P2 =
Columns 1 through 5

-0.0308 0.3500 -1.3292 1.9000 0.6100

Column 6

3.4000

>>

You might also like