# Plotxy ok xplotyplot k linewidth 2 markersize 8

• 363
• 100% (5) 5 out of 5 people found this document helpful

This preview shows page 232 - 240 out of 363 pages.

plot(x,y, 'ok' ,xplot,yplot, 'k' , 'linewidth' ,2, 'markersize' ,8) xlabel( 'x' , 'fontsize' ,18) ylabel( 'y' , 'fontsize' ,18) 0 5 10 15 20 25 2 3 4 5 6 7 8 9 10 11 12 x y 0 5 10 15 20 25 2 3 4 5 6 7 8 9 10 11 12 x y
32 Chapter 8: Solved Problems 24. c Script File: x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2]; y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2]; p1=polyfit(x,y,3); xplot=linspace(0,24,100); yplot=polyval(p1,xplot); plot(x,y, 'ok' ,xplot,yplot, 'k' , 'linewidth' ,2, 'markersize' ,8) xlabel( 'x' , 'fontsize' ,18) ylabel( 'y' , 'fontsize' ,18) 24. d Script File: x=[1 2.2 3.7 6.4 9 11.5 14.2 17.8 20.5 23.2]; y=[12 9 6.6 5.5 7.2 9.2 9.6 8.5 6.5 2.2]; p1=polyfit(x,y,5); xplot=linspace(0,24,100); yplot=polyval(p1,xplot); plot(x,y, 'ok' ,xplot,yplot, 'k' , 'linewidth' ,2, 'markersize' ,8) xlabel( 'x' , 'fontsize' ,18) ylabel( 'y' , 'fontsize' ,18) 0 5 10 15 20 25 -2 0 2 4 6 8 10 12 14 x y 0 5 10 15 20 25 0 2 4 6 8 10 12 14 16 18 x y
Chapter 8: Solved Problems 33 Problem 25 ( a ) Script file : h=0:3000:33000; Den=[1.2 0.91 0.66 0.47 0.31 0.19 0.12 0.075 0.046 0.029 0.018 0.011]; plot(h, Den, 'ok' ) xlabel( '\fontsize{16}Height (m)' ) ylabel( '\fontsize{16}Density (kg/m^3)' ) figure semilogx(h, Den, 'ok' ) xlabel( '\fontsize{16}Height (m)' ) ylabel( '\fontsize{16}Density (kg/m^3)' ) figure semilogy(h, Den, 'ok' ) xlabel( '\fontsize{16}Height (m)' ) ylabel( '\fontsize{16}Density (kg/m^3)' ) figure loglog(h, Den, 'ok' ) xlabel( '\fontsize{16}Height (m)' ) ylabel( '\fontsize{16}Density (kg/m^3)' ) When the script file is executed four Figure Windows with the following figures open. 0 0.5 1 1.5 2 2.5 3 3.5 x 10 0 0.2 0.4 0.6 0.8 1 1.2 1.4 Height (m) Density (kg/m 3 )
34 Chapter 8: Solved Problems ( b ) Fit the data with exponential function since the data points in the third plot appear to approximately be along a straight line. Script file: (Determines the constants of the exponential function that best fits the data, and then plots the function and the points in a linear axes plot.) h=0:3000:33000; Den=[1.2 0.91 0.66 0.47 0.31 0.19 0.12 0.075 0.046 0.029 0.018 0.011]; p=polyfit(h,log(Den),1); m=p(1) 10 3 10 10 5 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Height (m) Density (kg/m 3 ) 0 0.5 1 1.5 2 2.5 3 3.5 x 10 10 -2 10 -1 10 0 10 1 Height (m) Density (kg/m 3 ) 10 3 10 10 5 10 2 10 1 10 0 Height (m) Density (kg/m 3 )
Chapter 8: Solved Problems 35 b=exp(p(2)) heq=linspace(0,33000,100); Deq=b*exp(m*heq); plot(h, Den, 'ok' ,heq,Deq, 'k' ) xlabel( '\fontsize{16}Height (m)' ) ylabel( '\fontsize{16}Density (kg/m^3)' ) Command Window: m = -1.4584e-004 b = 1.5302 The function is: The following figure is displayed: D 1.5302 e 1 4584 10 4 × ( ) h = 0 0.5 1 1.5 2 2.5 3 3.5 x 10 0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 Height (m) Density (kg/m 3 )
36 Chapter 8: Solved Problems Problem 26 User-defined function: function [b,m]=powerfit(x,y) p=polyfit(log(x),log(y),1); m=p(1); b=exp(p(2)); Script File: x=[0.5 2.4 3.2 4.9 6.5 7.8]; y=[0.8 9.3 37.97 68.2 155 198]; [b, m]=powerfit(x,y) xp=linspace(0.5,7.8,50); yp=b*xp.^m; plot(x,y, 'ok' ,xp,yp, 'k' , 'linewidth' ,2, 'markersize' ,12) xlabel( 'x' , 'fontsize' ,18) ylabel( 'y' , 'fontsize' ,18) Command Window: b = 2.7808 m = 2.0496 Figure displayed: 0 1 2 3 4 5 6 7 8 0 20 40 60 80 100 120 140 160 180 200 x y
Chapter 8: Solved Problems 37 Problem 27 Script File: T=[-20 0 40 100 200 300 400 500 1000]; TK=T+273.15; meu=[1.63 1.71 1.87 2.17 2.53 2.98 3.32 3.64 5.04]*1e-5; y=TK.^(3/2)./meu; a=polyfit(TK,y,1) C=1/a(1) S=C*a(2) Tp=-20:2:1000; TpK=Tp+273.15; meup=C*TpK.^(3/2)./(TpK+S); plot(T,meu, 'o' ,Tp,meup) xlabel( 'Temperature (^oC)' ) ylabel( 'Viscosity (N-s/m^2)' ) Command Window: a = 1.0e+007 * 0.0638 9.4479 C = 1.5682e-006 S = 148.1622 -200 0 200 400 600 800 1000 1.5 2 2.5 3 3.5 4 4.5 5 5.5 x 10 -5 Temperature ( o C) Viscosity (N-s/m 2 )
38 Chapter 8: Solved Problems Problem 28 ( a ) Script File: v=[5:10:75]; FE = [11 22 28 29.5 30 30 27 23]; p=polyfit(v,FE,2); xp=linspace(5,75,100); yp=polyval(p,xp); plot(v,FE, 'o' ,xp,yp) xlabel( 'v (mi/h)' ) ylabel( 'FE (mpg)' ) legend( 'Data' , 'Model' ,0)