Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7900985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:06:15+00:00 2026-06-03T09:06:15+00:00

I wrote the code for the secant algorithm , and now I have the

  • 0

I wrote the code for the secant algorithm , and now I have the function :

f(x) = 2x^3 - 4x^2 + 3x , with two initial points : x0 = -1 , x1 = 2 .

My question is how can I plot the function that I wrote ,i.e. secant , with the function above , f , and the results below , in one graph ?

Is it even possible to do that ?

The results that I got after I used the secant algorithm , are :

    v =
   -4.0000
    2.2069
    2.3699
    2.6617
    2.5683
    2.5804

Those are 6 iterations that I used on my secant algorithm , for the given x0 & x1 above .

I’d appreciate if you can explain .

EDIT :

This is the code that I used in order to get the results :

[z,n,v]=secant([-1,2],10^(-5),10^(-5),10)

for the prototype :

function [x,n,v]=secant(X,d,e,N)

% x0 is the first point
% x1 is the end point 
% d is the tolerance 
% e is the requested precision 
% N is the number of iterations 

Thanks .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:06:16+00:00Added an answer on June 3, 2026 at 9:06 am

    I quickly threw this together, it illustrates the powerful anonymous function
    and it shows you how to plot the results of the secant function (the same way as on wikipedia: http://en.wikipedia.org/wiki/File:Secant_method.svg)

    What I don’t understand however is why your secant function has both a tolerance and a requested precision as an input; I would think the tolerance is the result of the secant algorithm..

    function [  ] = tmp1(  )
    
        f=@(x) x.^2;
        [xend,n,v]=secant(f,-4,3,1e-4,50);
        fprintf('after %d iterations reached final x_end = %g, f(x_end) = %g\n',n,xend,f(xend))
    
    
        figure;hold on;
        xtmp = linspace(min(v),max(v),250);
        plot(xtmp,f(xtmp),'r'); % plot the function itself
        line([v(1:end-2) v(3:end)]',[f(v(1:end-2)) zeros(n+1,1)]','Color','b','Marker','.','MarkerEdgeColor','b'); % plot the secant lines
        plot(v,f(v),'.','MarkerEdgeColor','r')% plot the intermediate points of the secant algorithm
        line([v(3:end) v(3:end)]',[zeros(n+1,1) f(v(3:end))]','Color','k','LineStyle','--'); % vertical lines
    
        ylim([-4 max(f(xtmp))]); % set y axis limits for nice plotting view algorithm
    
    end
    
    function [xnew,n,v]=secant(f, x0,x1,e,N)
    % x0 is the first point
    % x_end is the end point
    % e is the requested precision
    % N is the number of iterations
    
    v=zeros(N+2,1);
    v(1)=x0;
    v(2)=x1;
    
    for n=0:N-1
        xnew = x1 - f(x1) * (x1-x0)/(f(x1)-f(x0));
        v(3+n) = xnew;
        if abs(f(xnew)) <e
            break;
        else
            x0=x1;
            x1=xnew;
        end
    end
    v(n+4:end)=[];
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a Com server and I have wrote code that detect situation
I have a dropdown.Basing on this dropdown i shud load another dropdown.i wrote code
I wrote code that fails to use the JQuery autocomplete to fire a result
Simple question. A friend of mind wrote code similar to this one (which is
i have wrote code for quicksort with linked list ,here is code #include<stdio.h> #include<iostream>
I always run in circles with this problem. i wrote code that uses the
I wrote code for one application.In that I wrote IME_ACTION_DONE for edit text.All other
I wrote code for matching filepath which have extenstion .ncx , pattern = Pattern.compile($(\\|\/)[a-zA-Z0-9_]/.ncx);
I try to wrote code that read data from stdin: size_t bufSize = 1024;
Background: I wrote code that will output all the currently logged in User's Active

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.