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 6716201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:42:18+00:00 2026-05-26T08:42:18+00:00

Im running a simple script to estimate roots for a function. Everything works great,

  • 0

Im running a simple script to estimate roots for a function. Everything works great, each iteration of the algorithm prints off the current x and f(x), but when the script finishes and sets the final estimate of x as the output of the function the value is returned and rounded to 3 decimal places…

while k < maxit
    k = k + 1;
    dx = b - a;
    xm = a + 0.5*dx;       %  Minimize roundoff in computing the midpoint

    fm = feval(fun, xm, diameter, roughness, reynolds);

    fprintf('%4d  %12.20e  %12.4e\n',k,xm,fm); 

    if (abs(fm)/fref < feps) | (abs(dx)/xref < xeps) % True when root is found
        r = xm;  
    return;
end

here is the tail bit of the output:

k       xm            fm
45  6.77444446476613980000e-003   1.3891e-012
46  6.77444446478035060000e-003  -1.3380e-011
47  6.77444446477324520000e-003  -5.9952e-012
48  6.77444446476969250000e-003  -2.3022e-012
49  6.77444446476791610000e-003  -4.5830e-013

    ans =

        0.0068

i dont know why its rounding the output…. how do i prevent that?

  • 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-05-26T08:42:18+00:00Added an answer on May 26, 2026 at 8:42 am

    try typing ‘format longE’ in the command line before running the script

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I'm running a simple Ruby script, what's the easiest way to dump an
We are running a very simple Symfony script, that randomly returns an Error 500.
I've written a simple perl script that I'm running via fastCGI on Apache. The
I have a quite simple perl script, that in one function does the following:
I'm running a simple python script sending data to a mongodb #!/usr/bin/env python import
I have created a simple bash script, chmod +x, and successfully am running it
I'm running a simple script to connect to the serial port of my electricity
I'm trying to get Capybara running in a simple Ruby script -- i.e. without/outside
I'm running OSX 10.6, and I have this very simple script in a file
I'm having trouble running a simple bash script from Java. Specifically: ... try{ ProcessBuilder

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.