1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Rep Power

    Help me with program.

    Hello, i have a task, and i need your help
    Write a C function that calculates the value of mathematical functions:
    f (x) = 0.1 x2 - x ln x.
    Function prototype should be:
    float f (float x).

    Change the program p4_7.c that she wouldn't search the polynomial, but the roots of this new function. Try the program by finding roots of functions in the range [1, 2].

    I can't program at all, so i will be very pleased if someone will help me. But please, try to write this program using basic syntax, not the advanced or something.

    /* p4_7.c */
    /* Program chapter4_7 */
    /* */
    /* This program estimates the real roots of a */
    /* polynomial function using incremental search. */

    #include <stdio.h>
    #include <math.h>

    /* Declare function prototypes. */
    void check_roots(double left,double right,double a0,
    double a1,double a2,double a3);
    double poly(double x,double a0,double a1,
    double a2,double a3);

    int main(void)
    /* Declare variables. */
    int n, k;
    double a0, a1, a2, a3, a, b, step, left, right;

    /* Get user input. */
    printf("Enter coefficients a0, a1, a2, a3: \n");
    scanf("%lf %lf %lf %lf",&a0,&a1,&a2,&a3);
    printf("Enter interval limits a, b (a<b): \n");
    scanf("%lf %lf",&a,&b);
    printf("Enter step size: \n");

    /* Check subintervals for roots. */
    n = ceil((b - a)/step);
    for (k=0; k<=n-1; k++)
    left = a + k*step;
    if (k == n-1)
    right = b;
    right = left + step;

    /* Exit program. */
    return 0;
    /* This function checks a subinterval for a root. */
    void check_roots(double left,double right,double a0,
    double a1,double a2,double a3)
    /* Declare variables. */
    double f_left, f_right;

    /* Evaluate subinterval endpoints and test for roots. */
    f_left = poly(left,a0,a1,a2,a3);
    f_right = poly(right,a0,a1,a2,a3);
    if (fabs(f_left) < 0.1e-04)
    printf("Root detected at %.3f \n",left);
    if (fabs(f_right) < 0.1e-04)
    if (f_left*f_right < 0)
    printf("Root detected at %.3f \n",(left+right)/2);

    /* This function evaluates a cubic polynomial. */

    double poly(double x,double a0,double a1,double a2,double a3)
    return a0*x*x*x + a1*x*x + a2*x + a3;
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power
    /* assume x2 means x squared */
    #define F float
    F f(F x){F logf(F);return x*(x/10-logf(x));}
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Rep Power
    I can't program at all
    So why do you have this very specific task? Cheating on your homework because you didn't bother going to class all semester?
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  6. #4
  7. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Rep Power
    > I can't program at all,
    As noted.

    > so i will be very pleased if someone will help me.
    Will your future employer be as pleased when they realise you're a fake?

    > But please, try to write this program using basic syntax, not the advanced or something.
    Well we wouldn't want to make it too obvious that you didn't write it now do we :rolleyes:

    Not that you've written anything so far, since what you posted seems to be yet another ctrl-a/ctrl-c/ctrl-v job.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    Plagiarism is the academic crime of submitting somebody else's work as your own.

    Every time you ask somebody else to do your homework for you, you are attempting to commit plagiarism and you are trying to make others complicit in that crime of plagiarism.

    If you are caught committing plagiarism, you are subject to dismissal from your school. That should be documented in your academic record, which will be read by all other schools that you will try to enroll in after your expulsion. Those of us whom you had made complicit in your crime of plagiarism will however go unpunished, since we are either already working professionals or we are students who have ourselves not committed that unpardonable crime of plagiarism.

    You are holding a straight-razor to your own academic throat. Are you truly ready to draw that blade across your own academic throat? Are you truly ready to commit academic suicide? Your professors are not idiots, regardless of how they sound in class. They know the power of Google as does salem here. We have had professors post messages here telling us that they have found their students posting here asking for us to do their work for them and that they had a very good idea who they were. Your professors are not idiots. They will find you out.

    I will now help you: Do your own homework! If you have difficulties with your own homework, then we can help you with that, but your homework must always be your own work!

IMN logo majestic logo threadwatch logo seochat tools logo