Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %Get the input for the function and the convergence criteria
- sfnc = input('Enter the function : ', 's');
- fnc = inline(sfnc, 'x');
- criteria = input('Enter the convergence criteria : ');
- fa = 1;
- fb = 1;
- %Decide on an interval using input and checking whether a root definitely
- %exists within it
- while ((fa*fb) > 0) %loops while the statement is false, when true it stops
- %and the message below is displayed in the if statement.
- a = input('Enter the lower limit of the interval : ');
- b = input('Enter the upper limit of the interval : ');
- fa = fnc(a);
- fb = fnc(b);
- x1=a;
- x2=b;
- xtrue = fzero(fnc, [b a]); %determines the true root of the function between [a,b]
- clc
- if ((fa*fb) > 0)
- display('Please enter an interval such that f(a)*f(b) is negative.');
- end;
- end
Add Comment
Please, Sign In to add comment