Thread: c language and numerical methods questions ??

  1. #1
    Registered User
    Join Date
    Oct 2015
    Posts
    39

    c language and numerical methods questions ??

    i have been trying to follow computer oriented numerical methods in c language for some time now ...

    we had lots of maths to cover ... and we lacked proper materials ...

    so i had to make notes myself , because most of the text books were lacking the example programs and the maths...

    these were the things in my syllabus

    mathematical expressions
    equations in one variable
    equations in two variables
    system of 2 equations containing 2 variables
    functions in one variable
    functions in two variables

    differential equations

    first order differential equations
    second order differential equations
    higher order differential equations ...

    linear differential equations
    separable differential equations
    exact differential equations
    homogeneous differential equations
    non homogeneous differential equations
    using the method of undetermined coefficients ...



    partial differential equations ...
    Numerical Methods and errors
    Interpolation
    Numerical Differentiation
    Numerical Integration
    Solution of Algebraic and Transcendental Equations
    Numerical Solution of a system of Linear Equations
    Numerical Solution of Ordinary differential equations
    Curve fitting
    Numerical Solution of problems associated with Partial Differential Equations
    Solution of Algebraic and Transcendental Equation
    2.1 Introduction
    2.2 Bisection Method
    2.3 Method of false position
    2.4 Iteration method
    2.5 Newton-Raphson Method
    2.6 Ramanujan's method
    2.7 The Secant Method Finite Differences


    3.1 Introduction
    3.3.1 Forward differences
    3.3.2 Backward differences
    3.3.3 Central differences
    3.3.4 Symbolic relations and separation of symbols
    3.5 Differences of a polynomial Interpolation
    3.6 Newton's formulae for intrapolation
    3.7 Central difference interpolation formulae
    3.7.1 Gauss' Central Difference Formulae
    3.9 Interpolation with unevenly spaced points
    3.9.1 Langrange's interpolation formula
    3.10 Divided differences and their properties
    3.10.1 Newton's General interpolation formula
    3.11 Inverse interpolation Numerical Differentiation and Integration


    5.1 Introduction
    5.2 Numerical differentiation (using Newton's forward and backward formulae)
    5.4 Numerical Integration
    5.4.1 Trapizaoidal Rule
    5.4.2 Simpson's 1/3-Rule
    5.4.3 Simpson's 3/8-Rule Matrices and Linear Systems of equations
    6.3 Solution of Linear Systems – Direct Methods
    6.3.2 Gauss elimination
    6.3.3 Gauss-Jordan Method
    6.3.4 Modification of Gauss method to compute the inverse
    6.3.6 LU Decomposition
    6.3.7 LU Decomposition from Gauss elimination
    6.4 Solution of Linear Systems – Iterative methods
    6.5 The eigen value problem
    6.5.1 Eigen values of Symmetric Tridiazonal matrix Numerical Solutions of Ordinary Differential Equations


    7.1 Introduction
    7.2 Solution by Taylor's series
    7.3 Picard's method of successive approximations
    7.4 Euler's method
    7.4.2 Modified Euler's Method
    7.5 Runge-Kutta method
    7.6 Predictor-Corrector Methods
    7.6.1 Adams-Moulton Method
    7.6.2 Milne's method
    for example , for a polynomial ...

    a solution of a polynomial equation is also called a root of the polynomial ...

    a value for the variable that makes the polynomial zero

    if you can't find an exact expression, then you can use numerical methods to get approximations ...

    with numerical methods you can choose how close to zero you want, and it will give you a value that's at least that close ...
    The (standard) calculus is broken into two pieces.

    i) Differential calculus - which is looking at the instantaneous rates of change of objects with respect to some variables. We have the notion of the derivative of a function.
    ii) Integral calculus - which is calculating the area under curves, calculating volumes and so on. This is all given in terms if the (indefinite or definite) integral of a function.

    The two notions are tied together via the fundamental theorem of calculus. This says that the derivative and indefinite integral are basically mutual inverses (but not quite).
    An equation containing the derivatives of one or more dependent variables, with respect to one or more independent variables, is said to be a differential equation

    i have managed it this far ...

    there were at least 5 books i had to follow ..to understand this properly ...

    Peter Selby, Steve Slavin Practical Algebra_ A Self-Teaching Guide
    Tom M. Apostol Calculus, Volume I_ One-Variable Calculus, with an Introduction to Linear Algebra
    Tom M. Apostol Calculus, Volume II_ Multi-Variable Calculus and Linear Algebra, with Applications to Differential Equations and Probability
    Computer oriented numerical methods - N Datta
    Computer Fundamentals and Programming in C - J.B. Dixit
    c language and numerical methods questions ??-maths-jpg

    at this point of time i am not sure how the alphabets , variables , arrays ... etc ... are declared ??

    how do i declare ,
    f(x) ... theta , d^2y/dx^2 , (dy/dx)^3 , integral symbol... etc properly in c language ??

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    My programs tend to be math intensive.

    For the greek symbols that are commonly used, I simply name the variables according to their english names:

    float theta;
    float omega;
    float delta;

    Some others are simple enough:

    float dx, dy;
    float a, b, c;
    float x, y;

    Things like math functions, f(x), and integrals are not represented directly in the language. These are represented by coded algorithms which solve the equation procedurely. Often these math functions are in the form of a C function. For example, there is no "square root" operator in C. There is however a square root function available in the math library:

    double sqrt(double x)

    These are simply named according to the function they provide.

    Integral exponentiation is most commonly done by using multiplies:

    x^2 would be x * x
    x^3 would be x * x * x

    Hope I understood the question

    -
    Last edited by megafiddle; 07-20-2016 at 09:16 PM.

  3. #3
    Registered User
    Join Date
    Oct 2015
    Posts
    39
    megafiddle ,

    thanks a lot for the answers ...

    i checked few of my old text books and "numerical methods lab" record books ... nothing proper is there ...

    none of these are properly there in any of the c language books i have read either ...

    i should look for some sample programs involving maths ... especially differentiation , integration , differential equations etc ...


  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    596
    Glad to help. You should be able to find example code for the common methods at least.

    They show up here in topics from time time:

    Euler's Method in C - almost works

    -

  5. #5
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Quote Originally Posted by delta View Post
    megafiddle ,

    thanks a lot for the answers ...

    i checked few of my old text books and "numerical methods lab" record books ... nothing proper is there ...

    none of these are properly there in any of the c language books i have read either ...

    i should look for some sample programs involving maths ... especially differentiation , integration , differential equations etc ...

    Are you trying to do this in C specifically, or just trying to do some numerical programming in any language? You could look at Maple or Mathematica, or even MATLAB/Octave which have built-in facilities to do calculus and much more.

    If you want to do (implement) everything yourself in C, there are many free numerical methods books online, just Google it. Here is one for MATLAB: https://www.math.ohiou.edu/courses/math3600/book.pdf

    Here's one for C, not a lot of examples though: http://www.sci.brooklyn.cuny.edu/~mate/nml/numanal.pdf

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    1,656
    Some of the items listed in the syllabus may not be related to programming.

    For the more common stuff, you can do a web search like "c example trapezoidal rule" , "c example simpson's rule", "c example runge kutta 4" (or "c example rk4"). A more complete set of examples can be found in book(s) called numerical recipes (seems to be multiple web sites for this now).

    For the less common stuff, you'll need to search by the name of the method. For example, I created a small document with example c like code at the end for least squares curve fitting using orthogonal polynomails.

    http://rcgldr.net/misc/opls.rtf

    There are also specialized subjects in math and computer science, such as finite field math, used for error correction and certain types of encryption (AES), although it's unlikely you'll encounter this depending on the school you go to. For example:

    Reed–Solomon error correction - Wikipedia, the free encyclopedia
    Last edited by rcgldr; 07-21-2016 at 06:35 PM.

  7. #7
    Registered User
    Join Date
    Oct 2015
    Posts
    39
    Quote Originally Posted by megafiddle View Post
    Glad to help. You should be able to find example code for the common methods at least.

    They show up here in topics from time time:

    Euler's Method in C - almost works

    -
    megafiddle ,

    thanks for the link ...

    we had few problems in our "numerical methods lab" record ...

    it was not much ... just 7 problems to solve ...

    https://s31.postimg.org/di9zccspn/maths.jpg

    but was lacking an overall depth .. few problems for polynomials ..
    a problem for integration
    a problem of differential equation ..

    and you were supposed to figure out the bigger picture for some depth all by yourself ...

    that was not exactly a good thing to follow for computer oriented numerical methods in c programming language ...

    maybe i should play around with these 7 programs a little bit more ...

    when we were trying to do this , we used to do this in turbo c ... such an annoying compiler IDE to look at ...

    nowadays i am using Dev c ++



    c language and numerical methods questions ??-dev_c-jpg




    anyway let me see , what i can do with these sample programs ...









    Quote Originally Posted by Epy View Post
    Are you trying to do this in C specifically, or just trying to do some numerical programming in any language? You could look at Maple or Mathematica, or even MATLAB/Octave which have built-in facilities to do calculus and much more.

    If you want to do (implement) everything yourself in C, there are many free numerical methods books online, just Google it. Here is one for MATLAB: https://www.math.ohiou.edu/courses/math3600/book.pdf

    Here's one for C, not a lot of examples though: http://www.sci.brooklyn.cuny.edu/~mate/nml/numanal.pdf
    Epy ,

    i am trying to play around with some sample programs from my
    "numerical methods lab " record books ...

    i am planning to use only c for sometime ... in Dev c++

    this one looks like a really nice book ...



    https://www.math.ohiou.edu/courses/math3600/book.pdf

    thanks for this book suggestion ...



    Quote Originally Posted by rcgldr View Post
    Some of the items listed in the syllabus may not be related to programming.

    For the more common stuff, you can do a web search like "c example trapezoidal rule" , "c example simpson's rule", "c example runge kutta 4" (or "c example rk4"). A more complete set of examples can be found in book(s) called numerical recipes (seems to be multiple web sites for this now).

    For the less common stuff, you'll need to search by the name of the method. For example, I created a small document with example c like code at the end for least squares curve fitting using orthogonal polynomails.

    http://rcgldr.net/misc/opls.rtf

    There are also specialized subjects in math and computer science, such as finite field math, used for error correction and certain types of encryption (AES), although it's unlikely you'll encounter this depending on the school you go to. For example:

    Reed–Solomon error correction - Wikipedia, the free encyclopedia
    rcgldr,

    thanks for the suggestions ...

    i will do that ...

    unfortunately our "numerical methods lab " record had only 7 problems to solve ...

    i am going to compile it and make it work first in Dev c++

    i hope it works


  8. #8
    Registered User
    Join Date
    Oct 2015
    Posts
    39
    just a little bit of an update ...

    this numerical methods and programming in c is making a little bit more sense ...

    a question usually starts like this ...

    https://s31.postimg.org/di9zccspn/maths.jpg

    let me add this note too ...

    Numerical Methods--Euler's Method



    An Example

    Say we were to solve the initial value problem:

    y′ = 2x

    y(0) = 0

    It's so simple, you could find a formulaic solution in your head, namely y = x2. On the other hand, say we were to use a numerical technique. (Yes, I know we don't know how to do this yet, but go with me on this for a second!) The resulting numerical solution would simply be a table of values. To get a better feel for the nature of these two types of solution, let's compare them side by side, along with the graphs we would get based on what we know about each one:

    c language and numerical methods questions ??-numerical_solutions-png


    Notice that the graph derived from the formulaic solution is smoothly continuous, consisting of an infinite number of points on the interval shown. On the other hand, the graph based on the numerical solution consists of just a bare eight points, since the numerical method used apparently only found the value of the solution for x-increments of size 0.2.


    Using Numerical Solutions

    So what good is the numerical solution if it leaves out so much of the real answer? Well, we can respond to that question in several ways:

    The numerical solution still looks like it is capturing the general trend of the "real" solution, as we can see when we look at the side-by-side graphs. This means that if we are seeking a qualitative view of the solution, we can still get it from the numerical solution, to some extent.

    The numerical solution could even be "improved" by playing "join-the-dots" with the set of points it produces. In fact this is exactly what some solver packages, such as Mathematica, do do with these solutions. (Mathematica produces a join-the-dots function that it calls InterpolatingFunction.)

    When actually using the solutions to differential equations, we often aren't so much concerned about the nature of the solution at all possible points. Think about it! Even when we are able to get formulaic solutions, a typical use we make of the formula is to substitute values of the independent variable into the formula in order to find the values of the solution at specific points. Did you hear that? Let me say it again: to find the values of the solution at specific points. This is exactly what we can still do with a numerical solution



    Code:
    #include<stdio.h>
    #include<math.h>
     
     
    main()
    {
                               
          float x;                                                                  /*defining variables*/
          float y;
          float h;
          float targetx;
           
          
           
          puts("This program will solve the differential equation y' = y - x \nusing Euler's Method with y(0)=1/2 \n\n");
          puts("Please enter the desired constant step size. (h-value)\n\n");
          scanf("%f", &h);                                                           /* Defining step size*/
          puts("\n\nNow enter the desired x-value to solve for y.\n\n");
          scanf("%f", &targetx);
           
          y = 0.5;
          x = 0.0;
           
          puts("\n\nX                Y");
           
          while ( x != targetx )
          {
           
          printf("\n\n%f     %f", x, y);
           
          y = y + ((y - x)*h);
           
          x= x+h;
          }
            
          printf("\n\n%f     %f\n", x, y);
           
          printf("\nThe value of y at the given x is %f.\n\n", y, h);
                
          system("pause");
           
    }
    c language and numerical methods questions ??-euler-jpg
    Last edited by delta; 07-26-2016 at 12:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 questions regarding C language
    By uin12345 in forum C Programming
    Replies: 2
    Last Post: 02-13-2016, 09:02 AM
  2. c++ and numerical methods
    By shah fahad in forum C++ Programming
    Replies: 3
    Last Post: 03-15-2015, 03:13 PM
  3. Two minor language questions
    By CodeMonkey in forum C++ Programming
    Replies: 6
    Last Post: 01-06-2009, 03:12 AM
  4. Can you inherit Methods into other methods?
    By bobbelPoP in forum C++ Programming
    Replies: 5
    Last Post: 08-02-2008, 08:32 AM
  5. Numerical Integration
    By Crazed in forum C Programming
    Replies: 13
    Last Post: 03-03-2008, 03:01 PM

Tags for this Thread