Question: Solve the following function for x = 1 . 3 7 by writing codes in MATLAB for each of the following cases: a ) Calculate
Solve the following function for x by writing codes in MATLAB for each of the following cases:
a Calculate the analytical result by simply placing x to the function in MATLAB. Provide the result with "format longG" to have long format without trailing zeros Do not round off anything during the solution for this case.
Assign the result for to the variable ytruelong".
b Provide the analytical result with significant digits. Use round command in MATLAB for this purpose with "significant" defined ie ytruerounded roundytruelong,"significant"
Calculate the absolute true percent relative error between this result and the analytical result calculated in a Round it to significant digits. Assign it to the variable "relerrorbrounded
c Calculate the analytical result by rounding each term individually to significant digits with round function in MATLAB.
For this purpose, calculate term and round it to digits for x Separately, calculate term and round it to digitsfor x Separately, calculate term and round it to digitsfor x Then, use with all rounded results to obtain the final result, and assign it to yc Round the final result to significant digits by ycrounded roundyc"significant"
For display purposes, use numstr to control the exact display of a number as a string with significant digits. Assign it to the variable ycroundeddisp".
Calculate the true percent relative error between this result ycrounded and the analytical result calculated in a as ytruelong". Round it to significant digits. Assign it to the variable "relerrorcrounded
d Write the same function as This is actually the same as the function above. Round each term individually to significant digits to get the result also in significant digits in this new function form.
For this purpose, calculate term x and round it to significant digits with round function. Seperately, multiply this result by x and sum ietermx and round it to significant digits with round function. Then, multiply term by x ie term termx and round it to significant digits with round function. Finally, subtract from the last term ie and round the final result with round function. Assign the rounded final result to ydrounded
For display purposes, use numstr to control the exact display of a number as a string with significant digits. Assign it to the variable ydroundeddisp".
Calculate the true percent relative error between this result ydrounded and the analytical result calculated in a as ytruelong". Assign it to the variable "relerrord
e Write an if statement to determine which rounding approach gives the best result compared to the error calculated in b
If error in b is smaller than error in c then b is better. Use dispRounding at b is better than c for this case. Otherwise, c is better. Use dispRounding at c is better than b in MATLAB to show your conclusion. If they are equal, then, dispRounding at b and c are the same' Use if elseif, else statements.
If error in b is smaller than error in c then b is better. Use dispRounding at b is better than d for this case. Otherwise, d
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
