Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Assignment Instructions The purpose of this assignment is to show that you can... « Demonstrate the ability to use "for" loops with a sequence of values. « Demonstrate the ability to use "while"...

1 answer below »
Assignment Instructions
The purpose of this assignment is to show that you can...
« Demonstrate the ability to use "for" loops with a sequence of values.
« Demonstrate the ability to use "while" loops with sentinel conditions.
The length of a curved continuous line (in blue below) may be approximated by the total length of a series of connected straight line segments (in orange below) from the
'n" of straight line segments increase, the approximation to the length of the curved line gets better.
| n=1 x n=2 ©
n=3 | A n=>5
start of a curve to the end of a curve. As the numbe
"He
For a curved line defined by the function y = f(x), points (x;y;) along the curve (at the endpoints of the
[ (xo, flxo)), (xq, (xq), wo (Xn, fixq))
straight line segments) would then be...
fxs)
Of a=xy, Xx; X, X3 Xg Xxs=b X
The length, L;, between two of these consecutive points [ ( x;.1, f(xi-1) ), (x;, f(x;)) ] would follow the Pythagorean theorem ( a? +b = ¢?)andbe equal to the
hypotenuse of the triangle.
y
fx)
Ay;
+ Li = /(A2)® + (Ay)?
f(x; 1) =
|

x
x
Xi-1 0

Where...
Az = 2; — 2, and Ay; = f(a) — f(zi1)
To get the total approximate curved line length we can then sum all of "n" straight line segment lengths.
n
Liotal = Yi L;
Which gives us...
Lit = Yioy Li = Yi 4/ XXXXXXXXXXAg)* = Ti yf (ei — 21)? + (Fm) — fw)?
To simply this approximation we can select points on the curve such that they are equally spaced along the x axis. This would lead to the same value Az for alli. Given a
eginning point on the curve of xg = a, an ending point on the curve of x, = b, and the number of straight line segments "n", this results in...
Putting it all together, we get...
Putting it all together, we get...

_ n _ n 2 2 n (b-a))\?2 2
Lua = Si I= Sy XXXXXXXXXXa0) = £1, XXXXXXXXXXFa) = fain)
THE EQUATION IS ...

Lia = Si (S52) + (Fe) — fai)?
...to the approximated total length of the curve defined by f(x) from ( a, f(a) ) to ( b, f(b) ) using "n" straight line segments.
We just need to decide how many straight line segments, "n", to use in the approximation. The more segments, the better the approximation.
For this homework assignment you will...
« Use the provided (see below) function called "myCurve" which takes one argument: a single value, "x'
en
. Assume is a number. This function returns a single value,
"y". Assume "y" is a number. The function used to get "y" given "x" is continuous.
= For example...
y = myCuzve (0) ;

« Create a function called "curveLengthApproxN" which takes three arguments: the starting x value of a curve, "xmin", the ending x value of a curve, "xmax", and the

..in that order. Assume the starting x value, "xmax", is greater than the ending x value, "xmin", and the number of segments, "

number of straight line segments, "
greater than or equal to 1. Compute the curve length, Lyot41, using the approximation method and equation shown at the beginning of this assignment. Return the

approximated total length of the curve as the result.
= Use "xmin" fo

= Use "xmax" fo
= Use the provided curved line function y = myCurve(x) for the curve function f(x).
= For example...
r = curveLengthApproxN(-10,10,1); $= XXXXXXXXXX
= DO THIS ONLY USING methods and practices demonstrated in class. These include...
= Sequences or Vectors.
= The functions "sqrt", "length"

= "if", "for", "while", "
eak", "continue" statements
= Arithmetic, relational and logical operations.
= DO NOT USE other built-in matlab functions.
= Such as..""diff", "integral", "sum", "cumsum", "prod", or other similar functions.
= If unsure, ask the instructor.
= HINT: See the examples "summation" and "mySqrt" in Lecture 7, and "myExp" and "horner" in Lecture 8.
« Create a function called "curveLengthApprox1INV" which takes three arguments: the starting x value of a curve, "xmin", the ending x value of a curve, "xmax", and the
in that order. Assume the starting x value, "xmax" is greater than the ending x value, "xmin", and the maximum

maximum number of straight line segments, "nmax"....
number of segments, "nmax", is greater than or equal to 1. Compute the curve length approximation using the function curveLengthApproxN(xmin,xmax,n) repeatedly
for multiple numbers of segment values from 1 through "nmax". Append each result of curveLengthApproxN(xmin,xmax,n) to a numeric vector. Return that numeric
vector of lengths as the result.
= For example...
rv = curvelLengthApproxINV(-10,10,2) ;
§=[ XXXXXXXXXX XXXXXXXXXX ]
$The first element is with n=1.
$The second element is with n=2.
= HINT: See the examples "getPositivesV" in Lecture 7.
« Create a function called "curveLengthApprox" which takes three arguments: the starting x value of a curve, "xmin", the ending x value of a curve, "xmax", and an
estimated e
or to try to achieve, "e"...in that order. This function should repeatedly call the function curveLengthApproxN(xmin,xmax,n) with "n" starting at 1 straight
line segment and increasing the number of segments by 1 until "the absolute difference between the cu
ent length approximation using "n" line segments and the
previous length approximation using "n"-1 line segments" is less the supplied e
or parameter,
amount of n segments that achieve the estimated e
or.
nen
Return as a result the last approximate length using the minimum
= When the number of cu
ent segments is 1, assume a previous length approximation of zero to get the absolute difference.
= For example...
r = curvelLengthApprox(-10,10,2); $= XXXXXXXXXX
= HINT: Use the "abs()" function to get the absolute value.
= HINT: If you create and run an infinite loop, press Control-C or Command-C to stop the function execution.
= HINT: See the examples "expW2" in Lecture 8.
« Give all your functions and scripts a descriptive help comment to inform the user of the arguments needed and result returned. which would be returned when using
the help command.
« At the end of every file, put a comment with your name, netid, and RUID.
After downloading and installing the provided files and creating the functions, do the following...
1. Start Matlab, you should see a bunch of windows all touching each other, with the biggest one labeled “Command Window”, as was demonstrated in lecture. Click in
Matlab's Command Window. Hit the return key and you should see a prompt printed by the computer:
After the prompt, type
diary homework3. txt
This will make everything that will be typed in the command window (by either you or Matlab) also be copied into the file homework. This file will be on the
computer where Matlab is really running,
2. In the command window, type
clear
Answered Same Day Oct 19, 2022

Solution

Baljit answered on Oct 20 2022
47 Votes
clea
format long
help myCurve
Function myCurve
strong
definition of function f(x)=x^2 +2
function will take value x and will return f(x)
help curveLengthApproxN
function curveLengthApproxN
strong
This function will return total approximate length
Its first argument is minimum value of x
Its second argument is maximum value of x
Its third argument is number of line segments
help curveLengthApprox1NV
function curveLengthApprox1NV
strong
This will return total approximate length vector for 1 to n length segments
Its first argument is minimum value of x
Its second argument is maximum value of x
Its third argument is number of line segments
help curveLengthApprox
function...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here