APPENDIX 1Sharing Your Work
A1.1 Introduction
At some point, you'll likely need to share your MATLAB work, either for assignments at school or with colleagues and supervisors at work. One option is to send copies of your original files and data, but some recipients might need more background information than normally provided with comment lines inserted in the code. In situations where you want users to interact with the code or you want to use a format for improved readability, MATLAB's Live Script and publishing tools can help you communicate more effectively.
The primary example in this appendix uses code from a previous chapter that calculated future values. Here's the code in a script without comments:
function fv=futureValueCalc3(i,t,pv)
i = input(['Enter the interest rate as a percentage'...
'\n(0.05, for 5 percent, for example): '])
if i < 0 || i > 0.20
fprintf('You entered %.4f\n',i)
fprintf('Is that correct?\n')
i=input('Please verify the interest rate: ')
end
t = input('Enter the number of periods as years: ')
if t < 0 || t > 50
fprintf('You entered %.1f\n',t)
fprintf('Is that correct?\n')
t=input('Please verify the period: ')
end
pv = input('Enter the amount in dollars: ')
if pv < 0
fprintf('You entered a negative ...
Get Foundations of Computational Finance with MATLAB now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.