Controlling Error and Conditional Statements:
Measuring error and the Residual:
If we are attempting to find a numerical solution of an equation f(x) = 0 then there are a few different ways we can measure the error of our approximation. The most direct way to calculate the error would be as:
{Error at step n} = en= xn− x
Where xn is the n-th approximation alsoxis the true value. Nevertheless we usually do not know thevalue of x, or we wouldn’t be trying to approximate it. This makes it not possible to know the errordirectly as well as so we must be more clever.
One possible strategy that habitually works is to run a program until the approximation xnstopschanging. The trouble with this is that sometimes doesn’t work. Just for the reason that the program stopchanging does not necessarily mean that xn is close to the true solution.
For Newton’s method we have the subsequent principle- At every step the number of significantdigits roughly doubles. While this is asignificant statement about the error (ever since it signifiesNewton’s method converges really quickly) it is to some extent hard to use in a program.
Rather than calculate how close xn is to x* in this and many other situations it is much more practicalto measure how close the equation is to being satisfied in other words how close yn= f(xn) is to0. We will use the quantity rn= f(xn) − 0, called the residual, in many different situations. Mostof the time we merely care about the size of rn, so we look at |rn| = |f(xn)|.
The if ... end statement
If we have a definite tolerance for |rn| = |f(xn)| then we are able to incorporate that into our Newtonmethod program using an if ... end statement-
function x = mynewton(f,f1,x0,n,tol)% Solves f(x) = 0 by doing n steps of Newton’s method starting at x0.% Inputs: f -- the function, input as an inline% f1 -- it’s derivative, input as an inline% x0 -- starting guess, a number% tol -- desired tolerance, prints a warning if |f(x)|>tol% Output: x -- the approximate solutionx = x0; % set x equal to the initial guess x0for i = 1:n % Do n timesx = x - f(x)/f1(x) % Newton’s formulaendr = abs(f(x))if r > tolwarning (’The desired correctness was not attained’)end
In this program if checks if abs(y) > tol is true or else else not. If it is true then it does the whole thingamong there and end. If not accurate then it omits ahead to end.
In the command window explains the function
> f = inline(’x^3-5’,’x’)
And its derivative
> f1 = inline(’3*x^2’,’x’).
Then utilize the program with n = 5, tol = .01, and x0 = 2. Next, change tol to 10−10 and repeat.The loop: while ... end
While the preceding program will tell us if it worked or not we still have to input n the number ofsteps to take. Therefore far for a well-behaved problem if we make n too small then the tolerance will notbe attained and we will have to go back as well as increase it or if we make n too big then the programwill take more steps than necessary.
One way to manage the quantity of steps taken is to iterate until the residual |rn| = |f(x)| = |y| issmall enough. In Mat lab this is merely accomplished with a while ... end loop.
function x = mynewtontol(f, f1, x0, tol)
x = x0; % set x equal to the initial guess x0y = f(x);while abs(y) > tol % Do until the tolerence is reached.x = x - y/f1(x) % Newton’s formulay = f(x)end
The statement while end is a loopalike to for end however instead of going through theloop a fixed number of times it keeps going so long as the statement abs(y) > tol is true.
One clear drawback of the program is that abs(y) might never get slighter than tol. If thishappens the program would carry onrunning over as well as over until we stop it. Try this by setting theforbearance to a really small number:
>tol = 10^(-100)
after that run the program again for f(x) = x3 − 5.
You are able to use Ctrl-c to stop the program when it’s stuck.
One way to evade an infinite loop is add a counter variable say i in addition to a maximum number ofiterations to the programs.
Utilizing the while statement this can be accomplished as:
function x = mynewtontol(f,f1,x0,tol)x = x0; i=0; % set x equal to the initial guess x0. set counter to zeroy = f(x);while abs(y) > tol & i < 1000 % Do until the tolerence is reached or max iter.x = x - y/f1(x) % Newton’s formulay = f(x)i = i+1;end
Latest technology based Matlab Programming Online Tutoring Assistance
Tutors, at the www.tutorsglobe.com, take pledge to provide full satisfaction and assurance in Matlab Programming help via online tutoring. Students are getting 100% satisfaction by online tutors across the globe. Here you can get homework help for Matlab Programming, project ideas and tutorials. We provide email based Matlab Programming help. You can join us to ask queries 24x7 with live, experienced and qualified online tutors specialized in Matlab Programming. Through Online Tutoring, you would be able to complete your homework or assignments at your home. Tutors at the TutorsGlobe are committed to provide the best quality online tutoring assistance for Matlab Programming Homework help and assignment help services. They use their experience, as they have solved thousands of the Matlab Programming assignments, which may help you to solve your complex issues of Matlab Programming. TutorsGlobe assure for the best quality compliance to your homework. Compromise with quality is not in our dictionary. If we feel that we are not able to provide the homework help as per the deadline or given instruction by the student, we refund the money of the student without any delay.
Respiration tutorial all along with the key concepts of Electron Transport and Oxidative Phosphorylation, Electron Transport, Chemiosmosis and ATP Synthesis, Anaerobic Respiration and Respiration of Lipids
Theory and lecture notes of Linear Bounded Automata all along with the key concepts of linear bounded automata, Finite Automata with External Storage, deterministic LBA. Tutorsglobe offers homework help, assignment help and tutor’s assistance on Linear Bounded Automata.
tutorsglobe.com electron affinity assignment help-homework help by online chemical periodicity tutors
Coupled Oscillations tutorial all along with the key concepts of Oscillations of two coupled masses, Differential Equation, Normal Coordinates and Normal Modes, Modulation of Coupled Oscillations, Energy of Two Coupled Masses, Two Coupled Pendulums, Inductively Coupled LC circuits
cell phone gives a wireless service that is hand held phone with built in antennas when we talk in a cell phone; cell phone registers our voice and converts the sound into radio waves.
In order to perform the operations that mentioned above the computer allocates the work between its several functional units.
Proper Care should be taken when checking the biasing voltage of old CRT that should be appropriate to the new CRT.
tutorsglobe.com long run average cost curve assignment help-homework help by online cost and revenue tutors
Theory and lecture notes of Architecture of DBMS all along with the key concepts of architecture of dbms, stages of the architecture, external level, conceptual vision, internal view. Tutorsglobe offers homework help, assignment help and tutor’s assistance on Architecture of DBMS.
ultrasound is cyclic sound pressure along with a frequency greater than the upper limit of human hearing.
Physical methods of structural Investigation tutorial all along with the key concepts of structural investigation of complexes, Electronic Spectroscopy, Ligand field Spectra, Tanabe-Sugano Diagrams, Vibrational Spectroscopy, Magnetic measurement and Types of Magnetic Behaviors
tutorsglobe.com breeding for disease resistance assignment help-homework help by online breeding experiments tutors
the working of the table fan is that they do not in fact decrease the temperature of the room but due the circulation and wind motion they effect in surface cooling and provide a breezy feeling.
theory and lecture notes of theory of ttl logic family all along with the key concepts of totem pole in ttl, ttl transistor switching trouble, solution of ttl switching trouble and assignment help. tutorsglobe offers homework help, assignment help and tutor’s assistance on theory of ttl logic family.
tutorsglobe.com humoral immunity assignment help-homework help by online immunity tutors
1938386
Questions Asked
3689
Tutors
1467795
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!