Skip to content

bra15003/ME_3255_Extra_Credit

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 

ME_3255_Extra_Credit_Problem

Extra Credit Assignment 2

User Radius (cm) Angle (deg)
bra15003 3 260
bra15003 8.5 50
bra15003 4.2 195
bra15003 4 10
bra15003 10 60
bra15003 2 160
bra15003 0 0
bra15003 3.5 165
bra15003 8 111.5
bra15003 6.3 327.2

Extra Credit Assignment 3

data=[1.0000 ,  53.0000 ,   1.0000
    2.0000 ,  57.0000 ,   1.0000
    3.0000  , 58.0000 ,   1.0000
    4.0000,  63.0000  ,  1.0000
    5.0000 ,  66.0000  ,       0
    6.0000 ,  66.8000  ,       0
    7.0000 ,  67.0000 ,        0
    8.0000 ,  67.2000  ,       0
    9.0000  , 68.0000 ,        0
    10.0000 ,  69.0000  ,       0
    11.0000 ,  69.8000 ,   1.0000
    12.0000 ,  69.8000  ,       0
    13.0000,   70.2000  ,  1.0000
    14.0000 ,  70.2000  ,       0
    15.0000 ,  72.0000  ,       0
    16.0000  , 73.0000  ,       0
    17.0000  , 75.0000  ,       0
    18.0000 ,  75.0000  ,  1.0000
    19.0000 ,  75.8000   ,      0
    20.0000  , 76.2000  ,       0
    21.0000 ,  78.0000    ,     0
    22.0000  , 79.0000,         0
    23.0000  , 81.0000   ,      0];

n=23;
x=data(:,3);
y=data(:,2);

initial_a=[0,0];
options = optimset('GradObj', 'on', 'MaxIter', 400);
% Run fminunc to obtain the optimal theta
% This function will return theta and the cost
[a] = ...
fminunc(@(a) sum(-y.*log(1./(1+exp(-a(1)-a(2).*x)))-(1-y).*log(1./(1+exp(-a(1)-a(2).*x)))), initial_a, options);

Part A

function [cost,grad]=cost_logistic(a,x,y)

n=23;
x=data(:,3);
y=data(:,2);

options = optimset('GradObj', 'on', 'MaxIter', 400);
% Run fminunc to obtain the optimal theta
% This function will return theta and the cost
[theta, cost] = ...
fminunc(@(a)(sum(-y.*log(1./(1+exp(-a.*x)))-(1-y).*log(1./(1+exp(-a.*x))))), initial_a, options);


t=a.*x;
sigma=1./(1+exp(-t));
cost=zeros(1,n);
grad=zeros(1,n);
for i=1:n
    cost(i)=sum(-y(i).*log(sigma(i))-(1-y(i)).*log(1-sigma(i)))
    grad(i)=sum(sigma(i)-y(i)).*x(i)
end
end

Part B

Output

  • a0 = 137.8472
  • a1 = 210.1783

Part C

plot(x,y, x, sigma(a(1)+a(2)*x))

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published