撰写MATLAB基础财务程式.PPT

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
撰写MATLAB基础财务程式

撰寫MATLAB基礎財務程式 撰寫MATLAB基礎財務程式 柯婷瑱 * 大綱 disp() fprintf() M檔 * disp(value) 提供顯示數值的方法 value 可為常數,變數,字串(一連串),陣列 Example num1=100; ch1=abcde; vector=[1,2,3,4,5]; disp(num1) disp(ch1) disp(輸出向量) disp(vector) disp([輸出向量,num2str(vector)]) 100 abcde 輸出向量 1 2 3 4 5 輸出向量(一連串)1 2 3 4 5 數值轉字串的方法 * fprintf(‘format’,value) 提供格式化輸出的方法 format為格式設定,value為欲輸出的資料。 format以%符號開頭的字元,將value以指定形式印出。value可為常數、變數或是任何形式的運算式。 常用格式 %d,以整數格式顯示數值 %e,以指數格式顯示數值 %f,以浮點數格式顯示數值 %g,以浮點數或指數格式顯示數值(以何者較短優先) \n,跳到新的一行 * Example num1=100; num2=13.8091; num3=1.288888888; ch1=abcde; fprintf(---show u the using format---\n) ---show u the using format--- fprintf(num1 is a int: %d\n,num1) num1 is a int: 100 fprintf(%s is a string\n,ch1) abcde is a string fprintf(%f is sum of num1 and num2\n,num1+num2) 113.809100 is sum of num1 and num2 fprintf(num2 with special format \%%20.8f\: %20.8f\n,num2) num2 with special format %20.8f: 13fprintf(num2 with format %%e is %e\n,num2) num2 with format %e is 1.380910e+001 fprintf(num2 with format %%g is %g\n,num2) num2 with format %g is 13.8091 * M檔 副檔名為 .m。檔案是文字檔,可以用各種文字編輯器修改,儲存時,需以文字模式儲存。 Script file 副檔名為m的檔案,包含 MATLAB各種指令 不支援輸入及輸出引數 運算過程產生的變數都存放在基本工作空間 Function file 也是m檔的一種,以function起頭的檔案 支援輸入及輸出引數 運算過程產生的變數都存放在函數本身的工作空間。變數為區域變數。 迴圈及流程控制語法 for 變數= 向量 運算式; end * if 條件式 運算式; else 運算式; end for i=1:4 disp(i); end a=2; if a=0 disp(‘+’); Else disp(‘-’); end * Script file example clear all % 清除workspace中所有變數 x = [1 4 -1 -5]; for i = 1:length(x) if x(i)0 fprintf(x(%g) = %g is positive\n, i, x(i)); else fprintf(x(%g) = %g is negative or zero\n, i, x(i)); end end x(1) = 1 is positive x(2) = 4 is positive x(3) = -1 is negative or zero x(4) = -5 is negative or zero 一直儲存在memory 中,或下達clear all清除 * Function file function average = func1(vector) % This is a simple function % %Usage of this function: %output = func1(input) %output is the average of the input vector input. average = sum(vector)/length(vector)

文档评论(0)

xiaozu + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档