Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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=1.37 by writing codes in MATLAB for each of the following cases:
a) Calculate the analytical result by simply placing x=1.37 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 "y_true_long".
b) Provide the analytical result with 3 significant digits. Use round command in MATLAB for this purpose with "significant" defined (i.e., y_true_rounded3= round(y_true_long,3,"significant"))
Calculate the absolute true percent relative error between this result and the analytical result calculated in a). Round it to 3 significant digits. Assign it to the variable "rel_error_b_rounded3".
c) Calculate the analytical result by rounding each term individually to 3 significant digits with (round) function in MATLAB.
For this purpose, calculate term1= and round it to 3 digits for x=1.37. Separately, calculate term2= and round it to 3 digitsfor x=1.37. Separately, calculate term3= and round it to 3 digitsfor x=1.37. Then, use with all rounded results to obtain the final result, and assign it to y_c. Round the final result to 3 significant digits by y_c_rounded3= round(y_c,3,"significant")
For display purposes, use num2str to control the exact display of a number as a string with 3 significant digits. Assign it to the variable "y_c_rounded3_disp".
Calculate the true percent relative error between this result (y_c_rounded3) and the analytical result calculated in a) as "y_true_long". Round it to 3 significant digits. Assign it to the variable "rel_error_c_rounded3".
d) Write the same function as . This is actually the same as the function above. Round each term individually to 3 significant digits to get the result also in 3 significant digits in this new function form.
For this purpose, calculate term1= x-7 and round it to 3 significant digits with (round) function. Seperately, multiply this result by x and sum 8(i.e.(term1*x)+8) and round it to 3 significant digits with (round) function. Then, multiply term2 by x (i.e., term3= term2*x) and round it to 3 significant digits with (round) function. Finally, subtract 0.35 from the last term (i.e.,) and round the final result with (round) function. Assign the rounded final result to "y_d_rounded3".
For display purposes, use num2str to control the exact display of a number as a string with 3 significant digits. Assign it to the variable "y_d_rounded3_disp".
Calculate the true percent relative error between this result (y_d_rounded3) and the analytical result calculated in a) as "y_true_long". Assign it to the variable "rel_error_d".
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 disp('Rounding at b is better than c') for this case. Otherwise, c is better. Use disp('Rounding at c is better than b') in MATLAB to show your conclusion. If they are equal, then, disp('Rounding 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 disp('Rounding at b is better than d') for this case. Otherwise, d

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions