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 50 51 52 53
|
//Project 2 - ENGR 110-02
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
//Introduce program to user
cout<<"Project 2\nThis program determines if a mast will buckle under its own weight using complex \
equations.\n";
//Declare variables
float l,y,lambda,xrootpls1,xrootmin1;
int x[10],fx[10],i;
//Get values from user
cout<<"Using the equation X=(4/9)*g*((lambda*L_3)/(Y*I_2)) to calculate if the mast will buckle, we\
must find X and L.\n";
//Calculate negative root of equation for X
for (i=0;i<=5;i+=0.25){
fx[0]=(pow(i,0)-(0.375*pow(i,1))+(0.028125*pow(i,2))-(0.0008789*pow(i,3))+(0.000012*pow(i,4)));
if (fx[0]<0){
fx[2]=(pow(i,0)-(0.375*pow(i,1))+(0.028125*pow(i,2))-(0.0008789*pow(i,3))+(0.000012*pow(i,4)));
x[2]=i;
break;
}
}
//Calculate posotive root of equation for X
for (i=0;i<=5;i+=0.25){
fx[0]=(pow(i,0)-(0.375*pow(i,1))+(0.028125*pow(i,2))-(0.0008789*pow(i,3))+(0.000012*pow(i,4)));
if (fx[0]<0){
i-=0.25;
fx[1]=(pow(i,0)-(0.375*pow(i,1))+(0.028125*pow(i,2))-(0.0008789*pow(i,3))+(0.000012*pow(i,4)));
x[1]=i;
break;
}
}
i=3;
x[i]=((x[i-1])-((fx[i-1]*(x[i-2]-x[i-1]))/(fx[i-2]-fx[i-1])));
//Ask user accuracy for X value
cout<<"\nTo what accuracy would you like X to be? (Default x4 trials)\nEnter number (+4): ";
cin>>i; //Get value stored in 'i' variable
for (i;i<=i+4;i++){
x[i]=((x[i-1])-((fx[i-1]*(x[i-2]-x[i-1]))/(fx[i-2]-fx[i-1])));
cout<<"\n"<<x[i];
}
cout<<"\n"<<fx[1];
}
|