C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 12th, 2012, 09:41 AM
saugiskis saugiskis is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 1 saugiskis User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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;
}
/*------------------------------------------------------------*/

Reply With Quote
  #2  
Old December 12th, 2012, 01:41 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is offline
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,389 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 14 h 22 m 25 sec
Reputation Power: 383
/* 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!

Reply With Quote
  #3  
Old December 12th, 2012, 05:45 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,477 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 7 h 25 m 53 sec
Reputation Power: 2194
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!

Reply With Quote
  #4  
Old December 13th, 2012, 01:08 AM
salem's Avatar
salem salem is offline
Contributed User
Click here for more information
 
Join Date: Jun 2005
Posts: 3,840 salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)salem User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 153 Folding Title: Novice Folder
Time spent in forums: 2 Months 3 Weeks 2 Days 19 h 25 m 12 sec
Reputation Power: 1774
> 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

Reply With Quote
  #5  
Old December 13th, 2012, 01:24 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is offline
Contributing User
Dev Shed God 2nd Plane (6000 - 6499 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 6,141 dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level)dwise1_aol User rank is General 15th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 2 Weeks 3 Days 23 h 52 m 21 sec
Reputation Power: 1974
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!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Help me with program.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap