Presentation is loading. Please wait.

Presentation is loading. Please wait.

Physics 114: Final Project Hints

Similar presentations


Presentation on theme: "Physics 114: Final Project Hints"— Presentation transcript:

1 Physics 114: Final Project Hints
John Federici NJIT Physics Department

2 TRIVIA QUESTION! What day of the year is usually celebrated by fans as ‘Star Wars Day’? (a) January 1 (b) March 20 (c) April 15 (d) May 4 (e) May 14

3 TRIVIA QUESTION! What day of the year is usually celebrated by fans as ‘Star Wars Day’? (a) January 1 – ‘A New Hope’ (b) March 20 – first day of Spring – ‘The Force Awakens’ (c) April 15 – Income Taxes due – ‘ The Empire Strikes Back’ (d) May 4 – ‘May the fourth be with you’ (e) May 14 – George Lucas Birthday

4 Text data Define a STRING by putting alphanumeric characters in ‘quotes’ >> year=2017; >> DateString='The year is '; >> TempString=[DateString,int2str(year),'. HAPPY NEW YEAR!']; >> disp(TempString) The year is HAPPY NEW YEAR! >> As you would expect, there is standard syntax to concatenate strings and to convert numeric data (eg. int2str, num2str, sprintf) to string data. Display a STRING with ‘disp’ NOTE: Some functions interpret a ‘FORMAT SPECIFIER Differently…

5 Text data - continued NOTE: Some functions interpret a ‘FORMAT SPECIFIER Differently… >> i=5; >> str1=int2str(i) str1 = 5 >> str2=num2str(i,'%3d') str2 = >> str3=sprintf('%3d',i) str3 = >> NOTE: for sprintf function, spaces PAD on the left to ensure that the string is 3 characters long while for num2str, the same format string DOES NOT PRODUCE SAME RESULTS

6 Array quirks Sometimes you will get an ERROR in matlab if the sizes of matrices do not match in a mathematical operation. For example if A is a 1 by N matrix and B is an N by 1 matrix, math operations such as multiplication and division will give errors. A trick is to TRANSPOSE one of the matrices. For example BT=transpose(B) Will convert B as a N by 1 matrix to a 1 by N matrix.

7 Programatically Saving Best Fit Parameters
In order to create an image of your best fit variable, you can use the following code: [fitresult, gof] = fit( xData, yData, ft, opts ); myImage(x,y)=fitresult.nr; The first line of code using the ‘fit’ function to fit the xData and the yData to the fit type defined by ‘ft’ with the options (eg. excluded points, starting values etc.) defined by ‘opts’. You can use the online help for more details and examples. The output variable ‘fitresult’ contains the results of the fits. Assuming that the real refractive index variable in the best fit is called ‘nr’, then the variable ‘fitresult.nr’ is the best fit value for the real refractive index.

8 Programatically Saving Best Fit Parameters
You can use the ‘confint’ command to report the confidence intervals (95%) for the best fit parameters: >> confint(fitresult) ans = Remember that in the sciences (and Physics), one usually describes error using 1 standard deviation (65% confidence level).

9 Reminder on using Histogram
Recall that the ‘histogram’ function ASSUMES that the data is a 1D vector. So that if you want a histogram of the 2D image data all together, you need to convert the 2D matrix of data into a 1D vector of data. To accomplish this, use the ‘reshape’ function.


Download ppt "Physics 114: Final Project Hints"

Similar presentations


Ads by Google