Permalink
Cannot retrieve contributors at this time
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?
curve_fitting/question2.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
44 lines (38 sloc)
1.23 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ------ Question 2 Script ------ % | |
clc; | |
clear; | |
oring = [ | |
1.00000 53.00000 1.00000 | |
2.00000 57.00000 1.00000 | |
3.00000 58.00000 1.00000 | |
4.00000 63.00000 1.00000 | |
5.00000 66.00000 0.00000 | |
6.00000 66.80000 0.00000 | |
7.00000 67.00000 0.00000 | |
8.00000 67.20000 0.00000 | |
9.00000 68.00000 0.00000 | |
10.00000 69.00000 0.00000 | |
11.00000 69.80000 1.00000 | |
12.00000 69.80000 0.00000 | |
13.00000 70.20000 1.00000 | |
14.00000 70.20000 0.00000 | |
15.00000 72.00000 0.00000 | |
16.00000 73.00000 0.00000 | |
17.00000 75.00000 0.00000 | |
18.00000 75.00000 1.00000 | |
19.00000 75.80000 0.00000 | |
20.00000 76.20000 0.00000 | |
21.00000 78.00000 0.00000 | |
22.00000 79.00000 0.00000 | |
23.00000 81.00000 0.00000 ]; | |
% Set options for fminunc | |
options = optimset('GradObj', 'on', 'MaxIter', 400); | |
temp = oring(:,2); | |
o_ringTF = oring(:,3); | |
% Run fminunc to obtain the optimal theta | |
% This function will return theta and the cost | |
[theta, cost] = fminunc(@(a)(cost_logistic(a, temp, o_ringTF)), [80 -1], options) | |
% part c' | |
e = exp(1); | |
sigma = @(t) 1./(1 + e.^(-t)); | |
plot(temp,o_ringTF,'o',temp,sigma(theta(1) + theta(2).*temp)) |