-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhessian.cpp
More file actions
49 lines (47 loc) · 1.35 KB
/
hessian.cpp
File metadata and controls
49 lines (47 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//hessian
//Sudharsan Neelamegam
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
float gf(float p,float q)
{
float h;
h=pow(p,3)+pow(q,3)+2*pow(p,2)+4*pow(q,2)+6; // Function given in the question
//h= 2*p*q+p-q+2*pow(p,2) + pow(q,2);
return h;
}
float gf();
int main()
{ float r[2][2]; // r is hessian matrix
int n;
cout<<"Enter the number of minimum points : ";
cin>>n;
float X[n],Y[n];
cout<<endl<<"Input the minimum points : "<<endl;
for (int j=0;j<n;j++)
{ cin>>X[j]>>Y[j];}
for(int i=0;i<n;i++)
{
r[0][0]=6*X[i]+4; //d2f/dx1
r[0][1]=0; //d2f/dx1dx2 //r is hessian matrix (put expression please)
r[1][0]=r[0][1];
r[1][1]=6*Y[i]+8; //d2f/dx2
float j1,j2;
j1=(r[0][0]);
j2=((r[0][0]*r[1][1])-(r[0][1]*r[1][0]));
cout<<"Point: ("<<X[i]<<","<<Y[i]<<")"<<endl<<"J1 :"<<ceil(j1)<<", J2:"<<ceil(j2)<<endl;
if(j1>0 && j2>0)
{
cout<<"RESULT : Positive Definite , Relative Minimum , Fn value : "<<gf(X[i],Y[i])<<endl<<endl;
}
else if(j1<0 && j2>0)
{
cout<<"Negative Definite , Relative Maximum , Fn value : "<<gf(X[i],Y[i])<<endl<<endl;
}
else
{
cout<<"Indefinite , Saddle point , Fn value : "<<gf(X[i],Y[i])<<endl<<endl;
}
}
return 0;
}