Homework 4

pdf

School

Stevens Institute Of Technology *

*We aren’t endorsed by this school

Course

ME 635

Subject

Mechanical Engineering

Date

Apr 3, 2024

Type

pdf

Pages

13

Uploaded by AgentCat6898

Report
Homework 3 By DIVYESH SOLANKI (20020446) Submitted to: Kishore Pochiraju Subject: MODELLING AND SIMULATION Date: 02-19-2024 DEPARTMENT OF MECHANICAL ENGINEERING STEVENS INSTITUTE OF TECHNOLOGY HOBOKEN, UNITED STATES
Table of Contents Problem 1 .............................................................................................. 3 Problem 2 .............................................................................................. 5 Problem 3 .............................................................................................. 9 Comparison between two Models. ................................................................................................... 12
Problem 1 Read the data from the csv file and plot the observations data in the files using MATLAB. In order to perform the linear regression first I need to see the data and it s behaviour in order to hypothese the model and fitting the given data into that model. For that I have used the following code in the MATLAB to plot the data on graph. % Reading Dataset 1,2,3 % dataset1=csvread( "C:\Users\solan\Downloads\Homework4_2024\Homework4_ 2024\Homework4_ME635_DataSet1.csv" ); dataset2=csvread( "C:\Users\solan\Downloads\Homework4_2024\Homework4_ 2024\Homework4_ME635_DataSet2.csv" ); dataset3=csvread( "C:\Users\solan\Downloads\Homework4_2024\Homework4_ 2024\Homework4_ME635_DataSet3.csv" ); x1=dataset1(:,1); y1=dataset1(:,2); x2=dataset2(:,1); y2=dataset2(:,2); x3=dataset3(:,1); y3=dataset3(:,2); figure hold on plot(x1,y1, '*' ) title( 'Dataset 1' ) hold off figure hold on plot(x2,y2, '*' ) title( 'Dataset 2' ) hold off figure hold on plot(x3,y3, '*' ) title( 'Dataset 3' ) hold off Using this code in MATLAB I was able to plot the data shown in the below graphs.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Problem 2 Based on the data plot, hypothesize a first model for the given datasets. Different models can be hypothesized based on your visualization. Find the best-fit parameters for each model error in the fits. Draw three plots that show the comparison between the first model and the corresponding observation data for each set. After plotting the data onto the graph, I have hypothesized different model for given three datasets as shown below. For the first model I have hypothesized the model y= a 1 x 2 +a 2 x+a 3 and used the following code to fit the data into the model and the found coefficient and errors are listed below. % Hypothesing funtion y= a1x*x+a2x+a3 for datase1 model1 xl=length(x1); A=[x1.*x1 x1 ones(xl,1)]; B=y1; coefficient=inv(A'*A)*A'*B y_model1=A*coefficient; figure hold on plot(x1,y1, '*' ) plot(x1,y_model1, '-' ) title( 'Fitting Dataset 1' ); legend( 'dataset 1' , 'Model 1' ) hold off
err=((y1-y_model1)./y_model1)'*((y1-y_model1)./y_model1) coefficient = -33.5011 43.6383 4.5865 err = 0.0072 Now for the dataset 2 I have hypothesized the function y= a 1 +a 2 sin(x) and the found coefficients and error are listed below. % Hypothesing funtion y=a1+a2sin(x)for datase2 model2 xl=length(x1); A=[ones(xl,1) sin(x2)];
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
B=(y2); coefficient3=inv(A'*A)*A'*B y_model4=A*coefficient3; figure hold on plot(x2,y2, '*' ) plot(x2,y_model4, '-' ) title( 'Fitting Dataset 2' ); legend( 'dataset 2' , 'Model 2' ) hold off err=((y2-y_model4)./y_model4)'*((y2-y_model4)./y_model4) coefficient3 = 11.6618 12.1233 err = 0.5590 For the dataset 3 I have hypothesized the model y= a 1 e a2x and I found the following values of co efficient and error. xl=length(x1);
A=[ones(xl,1) x3]; B=log(y3); coefficient5=inv(A'*A)*A'*B y_model6=exp(coefficient5(1,:))*exp(coefficient5(2,:)*x3); figure hold on plot(x3,y3, '*' ) plot(x3,y_model6, '-' ) title( 'Fitting Dataset 3' ); legend( 'dataset 3' , 'Model 1' ) hold off err=((y3-y_model6)./y_model6)'*((y3-y_model6)./y_model6) coefficient5 = 0.9759 3.3698 err = 0.9118
Problem 3 Based on the error and fit quality as seen in the solutions to problem 2, hypothesize refined (second) models that can potentially reduce the fit error. Find the best-fit parameters for the second set of models and the fitting errors. Draw three plots that show the comparison between the first model and the corresponding observation data for each set. Now in order to improve the model and reduce the error I have hypothesized the new function that can closely fit into our model. For the first dataset I have hypothesized the model y= a 1 x 3 +a 2 x 2 +a 3 x+a 4 . Using this function I have found following coefficients and the errors. % Hypothesing funtion y= a1x*x*x+a2x*x+a3x+a4 for datase1 model1 A=[x1.*x1.*x1 x1.*x1 x1 ones(xl,1)]; B=y1; coefficient1=inv(A'*A)*A'*B y_model2=A*coefficient1; figure hold on plot(x1,y1, '*' ) plot(x1,y_model2, '-' ) title( 'Fitting Dataset 1' ); legend( 'dataset 1' , 'Model 2' ) hold off err=((y1-y_model2)./y_model2)'*((y1-y_model2)./y_model2) coefficient1 =
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
-0.9141 -32.1221 43.0923 4.6286 err = 0.0061 For the dataset 2 I have hypothesized new model y=a1x^4+a2x^3+a3x^2+a4x+a5. Found values for the coefficient and error is listed below. % Hypothesing funtion y=a1x^4+a2x^3+a3x^2+a4x+a5 for datase2 model3 xl=length(x1); A=[x2.*x2.*x2.*x2 x2.*x2.*x2 x2.*x2 x2 ones(xl,1)]; B=y2; coefficient4=inv(A'*A)*A'*B y_model5=A*coefficient4; figure hold on plot(x2,y2, '*' ) plot(x2,y_model5, '-' ) title( 'Fitting Dataset 2' ); legend( 'dataset 2' , 'Model 3' )
hold off err=((y2-y_model5)./y_model5)'*((y2-y_model5)./y_model5) coefficient4 = 71.1156 -147.0433 68.1293 17.2342 8.5955 err = 0.1540 For the dataset I have Hypothesized y= . Found values of coefficients and error are listed below. % Hypothesing funtion y=xsinh(x) for datase3 model2 xl=length(x1); A=[x3 sinh(x3)]; B=y3; coefficient6=inv(A'*A)*A'*B y_model7=A*coefficient6;
figure hold on plot(x3,y3, '*' ) plot(x3,y_model7, '-' ) title( 'Fitting Dataset 3' ); legend( 'dataset 3' , 'Model 2' ) hold off err=((y3-y_model7)./y_model7)'*((y3-y_model7)./y_model7) coefficient6 = -188.0953 212.6065 err = 20.1249 Comparison between two Models.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help