当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

上海交通大学:《程序设计基础》课程教学讲义(密西根学院)Recitation Notes_recitation 13

资源类别:文库,文档格式:PDF,文档页数:2,文件大小:20.56KB,团购合买
点击下载完整版文档(PDF)

Example 1 function tokenList split(str,delimiter) tokenList ={} remain str; ii=1: while ~isempty(remain), [token,remain]strtok(remain,delimiter); tokenList(ii}token; ii =ii+1; end Example 2 function y upStairs(n) if n ==1 y=1: elseif n ==2 Y=2; elseif n ==3 Y=4; else y upstairs(n-1)+upstairs(n-2)+upstairs(n-3); end Example 3 Write a function,out combine(obj,n),which outputs all possible combinations of n characters from the characters in "obj"."obj"is a string and "n"is an integer.NO characters in "obj"are repeated. Please use recursion method. Sample Out combine (abcd',2) Out ab ac ad be bd cd Think about it yourselves.I will show you in the next recitation class. What if obj has repeated characters?Also think about arrangements of n characters instead of combinations with and without characters repeated

Example 1 function tokenList = split(str, delimiter) tokenList = {}; remain = str; ii = 1; while ~isempty(remain), [token, remain] = strtok(remain, delimiter); tokenList{ii} = token; ii = ii+1; end Example 2 function y = upStairs(n) if n == 1 y = 1; elseif n == 2 y = 2; elseif n == 3 y = 4; else y = upStairs(n-1) + upStairs(n-2) + upStairs(n-3); end Example 3 Write a function, out = combine(obj, n), which outputs all possible combinations of n characters from the characters in “obj”. “obj” is a string and “n” is an integer. NO characters in “obj” are repeated. Please use recursion method. Sample Out = combine(‘abcd’,2) Out = ab ac ad bc bd cd Think about it yourselves. I will show you in the next recitation class. What if obj has repeated characters? Also think about arrangements of n characters instead of combinations with and without characters repeated

Example 4 function heatConduction() tBar=[zeros(1,99),100]; time 1; old avg sum(tBar)/100; while true time time +1; tBar(time,1)=0; tBar(time,100)=100; tBar(time,2:99)=0.5 (tBar(time-1,1:98)+tBar(time-1,3:100)); new avg sum(tBar (time,:))/100; if abs(new avg -old avg)<0.005 break; end old avg new_avg; end tBar(end+1,end+1)=0; pcolor(1:101,1:time+1,tBar) colormap gray shading flat colorbar xlabel('Length'); ylabel('Time'); Color maps. hsv -Hue-saturation-value color map. hot Black-red-yellow-white color map. gray Linear gray-scale color map. bone -Gray-scale with tinge of blue color map. copper Linear copper-tone color map. pink Pastel shades of pink color map. white -All white color map. flag -Alternating red,white,blue,and black color map. lines Color map with the line colors. colorcube -Enhanced color-cube color map vga -Windows colormap for 16 colors. jet Variant of HSV. prism -Prism color map. cool -Shades of cyan and magenta color map. autumn Shades of red and yellow color map. spring -Shades of magenta and yellow color map. winter -Shades of blue and green color map. summer Shades of green and yellow color map

Example 4 function heatConduction() tBar = [zeros(1,99),100]; time = 1; old_avg = sum(tBar)/100; while true time = time + 1; tBar(time,1) = 0; tBar(time,100) = 100; tBar(time,2:99) = 0.5 * (tBar(time-1,1:98) + tBar(time-1,3:100)); new_avg = sum(tBar(time,:))/100; if abs(new_avg - old_avg) < 0.005 break; end old_avg = new_avg; end tBar(end+1,end+1) = 0; pcolor(1:101,1:time+1,tBar) colormap gray shading flat colorbar xlabel('Length'); ylabel('Time'); Color maps. hsv - Hue-saturation-value color map. hot - Black-red-yellow-white color map. gray - Linear gray-scale color map. bone - Gray-scale with tinge of blue color map. copper - Linear copper-tone color map. pink - Pastel shades of pink color map. white - All white color map. flag - Alternating red, white, blue, and black color map. lines - Color map with the line colors. colorcube - Enhanced color-cube color map. vga - Windows colormap for 16 colors. jet - Variant of HSV. prism - Prism color map. cool - Shades of cyan and magenta color map. autumn - Shades of red and yellow color map. spring - Shades of magenta and yellow color map. winter - Shades of blue and green color map. summer - Shades of green and yellow color map

点击下载完整版文档(PDF)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有