Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Output not suppressing (with semicolons)

Subject: Output not suppressing (with semicolons)

From: Kevin

Date: 10 May, 2014 23:26:09

Message: 1 of 2

f2 = @(x) x*exp(-x)-0.2;
[x_value y_value bisect_count] = bisect(f2,2,-5);

f2_der = @(x) (1-x)*exp(-x); % derivative of the function
x_tolerance = 10^-9;
y_tolerance = 10^-6;
newton_count = 0;
x0 = 0;
x1 = 10;
diff = 10;

while (diff > x_tolerance) || (f2(x1) > y_tolerance)
    
    newton_count = newton_count + 1;
    x1 = -(f2(x0)/f2_der(x0)) + x0;
    diff = abs(x0-x1);
    x0 = x1;
    
end

fprintf('The Newton Method converges faster. It found the value %1.5f after %1.0f iterations\n',x1,newton_count)
fprintf('while Bisect Method found the value %1.5f after %2.0f iterations.\n',x_value, bisect_count)
fprintf('The Newton Method converges way faster than the Bisection Method.\n\n\n')


OUTPUT:

x_value =

   0.259172439575195


y_value =

     7.647818980605070e-07


bisect_count =

    19

The Newton Method converges faster. It found the value 0.25917 after 5 iterations
while Bisect Method found the value 0.25917 after 19 iterations.
The Newton Method converges way faster than the Bisection Method.

Subject: Output not suppressing (with semicolons)

From: Phil Goddard

Date: 11 May, 2014 02:02:13

Message: 2 of 2

You haven't shown us the code for bisect.
Presumably there is a line in that function (whether deliberately or not) is missing a semi-colon.

Phil.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us