How to Create a Bisection Method Program for Arbitrary Functions?

In summary: This would make the program much more versatile.If you wanted to focus on specific types of functions (polynomials, for example), then you could ask the user to input the coefficients of each term (power of x). This would make the program much more versatile.
  • #1
rantz
4
0
help me please "numerical method"

please help me finish college assignment, I was given the task of creating programs numerical calculation method, the bisection method, the program c + + or Visual Basic, or any program language. last collection time Friday, 23 April 2010. please help me. please. help
 
Physics news on Phys.org
  • #2


You will have to show your effort so far, and be more specific about what precisely you need help with before we can help you.
 
  • #3


NeoDevin said:
You will have to show your effort so far, and be more specific about what precisely you need help with before we can help you.

I absolutely can not do it
 
  • #4


Which programming languages are you already familiar with?
What do you know about the bisection method?

Where precisely is your effort failing?
 
  • #5


NeoDevin said:
Which programming languages are you already familiar with?
What do you know about the bisection method?

Where precisely is your effort failing?

==> With c + +,
==> The method is applicable Pls We wish to solve the equation for the scalar variable x, Nowhere f is a continuous function.
The bisection method requires two initial points a and b and Standard and Poor That f (a) and f (b) have Opposite Signs. This Is Called a bracket of a root, for by the intermediate value theorem the continuous function f must have at least one root in the interval (a, b). The method now divides the interval in two by computing the midpoint c = (a + b) / 2 of the interval. Unless c is a root Itself - Which is very Unlikely, but possible - there are now two possibilities: either f (a) and f (c) have Opposite Signs and bracket a root, or f (c) and f (b ) Opposite Signs and brackets have a root. We select the subinterval That is a bracket, and Apply The Same bisection step to it. In this way the interval That Might contain a zero of f is reduced in width by 50% at Each step. We continue Until We have a bracket sufficiently small for our purposes.

I have some source code with c + + programming language ..
Can you help me?
 
  • #6


You should be able to write a while loop that runs until you reach your target accuracy/bracket size, using if statements to check your conditions.

Write some code, test it on some function, and if it doesn't work, post it here. I, or someone else here, will look it over and offer suggestions.
 
  • #7


NeoDevin said:
You should be able to write a while loop that runs until you reach your target accuracy/bracket size, using if statements to check your conditions.

Write some code, test it on some function, and if it doesn't work, post it here. I, or someone else here, will look it over and offer suggestions.

this is my source code

# Include <stdio.h>
# Include <math.h>
float f (float x)
(
return x + cos (x);
)

main ()
(
float a, b, c, T, error, e, iteration, the root;
int i;
char answer;
do
(
answer = 'y';
i = 1;
printf ("======================================== \ n");
printf ("Program Not Linear Equations Bisection \ n");
printf ("Version 1.0 =- -= \ n");
printf ("======================================== \ n");
printf ("Equation Function F (x) = x + cos (x) \ n");
printf ("Enter the initial guess of a ="); scanf ("% f", & a);
printf ("Input initial guesses b ="); scanf ("% f", & b);

printf ("f (a) =% f \ n", f (a));
printf ("f (b) =% f \ n", f (b));
if (f (a) * f (b) <0)
(
printf ("Enter the value of epsilon ="); scanf ("% f", & error);
printf ("iteration count -"); scanf ("% f", & iterations);
for (i = 1; i <= iterations; i + +)
(
e = abs, (b-a);
c = (a + b) / 2;
T = c + cos (c);
if (f (a) * T <0)
(
b = c;
)
else
(
a = c;
)
if (e <= error)
(
root = c;
)
)
printf ("The root of the equation x =% f \ n", c);
)
else
(
printf ("sorry calculation process is not subject to the terms \ n");
)
printf ("Do you want to repeat the y / t ="); scanf ("% s", & answer);
) While (answer == "y");
return 0;
)

I feel this is a very simple program, and all I want is a more complex program, like I could enter the function manually. My example program using the functions return x + cos (x);
My question how can I be able to enter the function as input.

It used to be, there are still many who need me ask again later.

thanks before
 
  • #8


Making the program be able to understand an arbitrary input function is not easy, as it has to be able to parse all the different functions and notations.

If you wanted to focus on specific types of functions (polynomials, for example), then you could ask the user to input the coefficients of each term (power of x).
 

Related to How to Create a Bisection Method Program for Arbitrary Functions?

1. What is a numerical method?

A numerical method is a mathematical algorithm or procedure used to solve problems that cannot be solved analytically. It involves using numerical calculations to approximate solutions to complex problems.

2. What are the advantages of using numerical methods?

Numerical methods allow for the efficient and accurate solution of complex problems that would be impossible or time-consuming to solve analytically. They also provide a way to analyze and understand real-world phenomena through mathematical models.

3. What are some common numerical methods used in science?

Some common numerical methods used in science include Newton's method for finding roots of equations, the Runge-Kutta method for solving differential equations, and the Monte Carlo method for simulating complex systems.

4. How do you choose the most appropriate numerical method for a problem?

The most appropriate numerical method depends on the specific problem and its characteristics. Factors to consider include the type of problem (e.g. differential equations, optimization), the complexity of the problem, the desired level of accuracy, and the available computing resources.

5. Can numerical methods be used for any type of problem?

No, numerical methods are not suitable for all types of problems. Some problems may have analytical solutions or may not be well-suited for numerical approximation. It is important to carefully consider the problem and its characteristics before choosing a numerical method.

Similar threads

  • Introductory Physics Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
  • Precalculus Mathematics Homework Help
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
1K
  • STEM Academic Advising
Replies
13
Views
2K
  • Programming and Computer Science
Replies
7
Views
1K
  • Atomic and Condensed Matter
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
5
Views
2K
Back
Top