Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
December 12th, 2012, 10:41 AM
 saugiskis
Registered User

Join Date: Dec 2012
Posts: 1
Time spent in forums: 9 m 11 sec
Reputation Power: 0
Help me with program.

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
/* 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");
scanf("%lf",&step);

/* 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;
else
right = left + step;
check_roots(left,right,a0,a1,a2,a3);
}

/* 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);
else
if (fabs(f_right) < 0.1e-04)
;
else
if (f_left*f_right < 0)
printf("Root detected at %.3f \n",(left+right)/2);

return;
}
/*------------------------------------------------------------*/
/* 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
December 12th, 2012, 02:41 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,153
Time spent in forums: 1 Month 3 Weeks 2 Days 8 h 27 m 2 sec
Reputation Power: 455
/* 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!

#3
December 12th, 2012, 06:45 PM
 ptr2void
I haz teh codez!

Join Date: Dec 2003
Posts: 2,530
Time spent in forums: 1 Month 2 Weeks 3 Days 18 h 48 m 26 sec
Reputation Power: 2336
Quote:
 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!

#4
December 13th, 2012, 02:08 AM
 salem
Contributed User

Join Date: Jun 2005
Posts: 4,258
Time spent in forums: 2 Months 4 Weeks 1 Day 14 h 22 m 54 sec
Reputation Power: 1827
> 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

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

#5
December 13th, 2012, 02:24 AM
 dwise1_aol
Contributing User

Join Date: Jan 2003
Location: USA
Posts: 6,857
Time spent in forums: 3 Months 1 Day 5 h 31 m 59 sec
Reputation Power: 2199
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.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Help me with program.