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