The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Help me with program.
Discuss Help me with program. in the C Programming forum on Dev Shed. Help me with program. C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 12th, 2012, 09:41 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 1
Time spent in forums: 9 m 11 sec
Reputation Power: 0
|
|
|
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
/* 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;
}
/*------------------------------------------------------------*/
|

December 12th, 2012, 01:41 PM
|
 |
Contributing User
|
|
|
|
|
/* 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!
|

December 12th, 2012, 05:45 PM
|
|
|
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!
|

December 13th, 2012, 01:08 AM
|
 |
Contributed User
|
|
|
|
> 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.
|

December 13th, 2012, 01:24 AM
|
 |
Contributing User
|
|
Join Date: Jan 2003
Location: USA
|
|
|
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!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|