Function that returns the Error

조회 수: 7 (최근 30일)
Lauren Passio
Lauren Passio 2021년 3월 25일
답변: Walter Roberson 2021년 3월 25일
I have to assign variable names to the following items:
  • Exact solution is 15.7214
  • Current approximation of the solution is 15.7813
  • Previous approximation of the solution is 15.9375
Than I have to write a function that returns the Relative True Error using TRE = 100*abs((exact-approx)/exact) and another function that returns the Absolute Relative Error using ARE= 100*abs((new-old)/new). I need to get the code correct before putting it into a function. I can only use:
  • abs()
  • function
  • for-end
  • fprintf
  • if-elseif-else-end
  • input
  • plot
  • size()
  • while-end
  • fprintf
The code I have so far is:
exact_sol = 15.7214;
current_approx_of_sol = 15.7813;
previous_approx_of_sol = 15.9375;
TRE = 100*abs((exact_sol-current_approx_of_sol)/exact_sol);
fprintf("The relative true error is %2.2g. \n", TRE)
ARE = 100*abs((new-previous_approx_of_sol)/new);
fprintf("The absolute relative error is %2.2g. \n", ARE)
I'm not sure if what to do about the "new" variable. I'm not sure if this is correct at all.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 3월 25일
In this context, old -> previous_approx_of_sol and new -> current_approx_of_sol

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by