Tutorial 2 solution

Tutorial 2 solution - Create an m-file for a function...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Name: _______________________ ID: __________________________ Hand in this sheet before leaving class. Write code to evaluate i 2 i = 1 10 using for. N = 10; sum = 0; for i = 1:N sum = sum + i^2; end disp(sum) Write code to evaluate i 2 i = 1 10 using while. N=10; i = 1; total = 0; while (i <= N) total = total + i^2; i = i + 1 end disp(sum) Write code to evaluate ( e 2 i + 1 i = 0 5 1) using for. N = 5; product = 1; for i = 1:N product = product * (exp(2* i + 1) – 1); end disp(product) Write code to evaluate ( e 2 i + 1 i = 0 5 1) using while. N=5; i = 0; prod = 1; while (i <= N) prod = prod * (exp(2* i + 1) – 1); i = i + 1 end disp(prod)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Create an m-file for a function dmsTOdec(d,m,s) that converts latitude or longitude given in degrees, minutes, seconds to the decimal equivalent. Use if. function w = dmstodec(d, m, s) % &lt;insert description&gt; % &lt;insert description&gt; if d &gt; 0 w = d + m/60 + s/3600; else w = d m/60 s/3600; end Test your m-file with these coordinates: 44 24 8.1606 = 44.40239182 78 13 21.5616 = 78.22265625 &gt;&gt; dmstodec(44, 24, 8.1606) ans = 44.4023 &gt;&gt; dmstodec(78, 13, 21.5616) ans = 78.2227...
View Full Document

Ask a homework question - tutors are online