473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Symbolic computation : the derivative of a quotient.

Symbolic computation : the derivative of a quotient.

Hello,

This time I try to simulate the derivative of a quotient.
The same function use the quotient rule if it is a quotient (f/g)
and the reciprocal rule if it is not a quotient. (1/g)

Into a text file,
I have an equation of this type.
I have created these equations
with the previous functions.

Examples:

eq01.txt:

@[ a*cos(2*x+3*x^2)*cos(2*n+3*a^2) : b*cos(2*x+3*a^2) ]

eq02.txt: (try this first:Quotient rule )

@[ a*f(x) : b*g(x) ]

eq03.txt: (try this first:Reciprocal rule )

@[ a*f(b) : b*g(x) ]
The functions
=============

is_a_quotient();

copy into "eq_n" the numerator.
copy into "eq_d" the denominator.
D_quotient();

Call the previous function,
and do the work.

See below my work.

Have I do some mistakes.
The result seem correct.

Thank.

/* ------------------------------------ */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* ------------------------------------ */
#define CHAR_N 1000
#define CHAR_A 2
/* ------------------------------------ */
int is_a_quotient(char *filename,char *eq_n,char *eq_d,char *x);
void D_quotient( char *filename,char *eq,char *x);
/* ------------------------------------ */
/* ------------------------------------ */
int main(void)
{
char filename[FILENAME_MAX];
char eq [CHAR_N];
char x [CHAR_A];

strcpy(x,"x");
strcpy(filename,"eq01.txt");

D_quotient(filename,eq,x);

printf("\n\n%s",eq);

getchar();
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */
int is_a_quotient(
char *filename,
char *eq_n,
char *eq_d,
char *x
)
{
/* ------------------------------------ */
FILE *f;
/* ------------------------------------ */
char c[CHAR_A];
/* ------------------------------------ */
int c_int;
int d; /* denominator True:1 Fault:0*/
int y; /* x True:1 Fault:0*/
int q; /* quotient True:1 Fault:0*/
/* ------------------------------------ */
strcpy( c,"");
strcpy(eq_n,"");/* numerator */
strcpy(eq_d,"");/* denominator */
/* ------------------------------------ */
q = 0;
y = 0;
d = 0;
/* ------------------------------------ */

f = fopen(filename,"r");

if (f==NULL) printf("File doesn't exist\n");
else

while( (c_int=getc(f))!=EOF )
{
c[0]=c_int;

if( !(strcmp(c,"\n"))||
!(strcmp(c," " ))||
!(strcmp(c,"@" ))||
!(strcmp(c,"[" ))||
!(strcmp(c,"]" )) )

strcpy(c,"");

else{
if( !(strcmp(c,x )) ) y=1;

if( !(strcmp(c,":")) )
{
d=1;
if(y)q=1;/* it is a quotient */
}
else /* no : */
if(d==0) strcat(eq_n,c); /* numerator */
else strcat(eq_d,c); /* denominator */
}
}

if(f!=NULL)fclose(f);

return (q);
}

/* ------------------------------------ */
void D_quotient(
char *filename,
char *eq,
char *x
)
{
/* ------------------------------------ */
char eq_n [CHAR_N];
char eq_d [CHAR_N];
/* ------------------------------------ */

strcpy(eq,"");

if(is_a_quotient(filename,eq_n,eq_d,x))
{
strcat(eq," @[");
strcat(eq,eq_n);
strcat(eq,"] [");
strcat(eq,eq_d);
strcat(eq,"]\n-\n [");
strcat(eq,eq_n);
strcat(eq,"] @[");
strcat(eq,eq_d);
strcat(eq,"]\n\n:\n\n [");
strcat(eq,eq_d);
strcat(eq,"]^2\n");
}
else
{
strcat(eq,"- [");
strcat(eq,eq_n);
strcat(eq,"] @[");
strcat(eq,eq_d);
strcat(eq,"]\n\n:\n\n [");
strcat(eq,eq_d);
strcat(eq,"]^2\n");
}
}

Mar 10 '07 #1
0 1476

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: daniel.wolff | last post by:
I am looking for a quick C program that takes n+1 pairs of values (integers) (a_i, f(a_i)), i=0,...,n, generates the coefficients \alpha_i, i=0,...,n of the polynomial of degree n that fits these...
1
by: solarin | last post by:
Hi, I've developed a program under VS 6.0. I can compile it and run it, but when I try to debbug , all my breakpoints are dissabled and I can see the following messages: Loaded...
3
by: xhunga | last post by:
Hello, This time I try to simulate the derivative of a product. Into a text file, I have an equation of this type. I have created these equations with the previous functions. Examples:
0
by: xhunga | last post by:
* Symbolic computation with the language c : The Derivative step by step. (Windows,Linux) You can find some examples into the file a_exampl.txt @ @
1
by: xhunga | last post by:
Hello, I have try symbolic algebra computation with list, in c language. (It is only for fun) This is the result of the example : c13.c /* ---------------------------------------- */ A_n :
4
by: Jon Harrop | last post by:
Can anyone improve this C++ program so that it can compete with the other languages: http://www.codecodex.com/wiki/index.php?title=Derivative -- Dr Jon D Harrop, Flying Frog Consultancy The...
1
by: amygrant1701 | last post by:
Hi, I've done this before so I don't see what I could doing wrong here. I'm running mysql 5x on freebsd. I'm using the default data directory of "/var/db/mysql" In there I have several dozen...
1
by: sora | last post by:
Hi, I've developed a MFC program under VS 6.0. My debugger *was* working fine and I've used it often for my project. Then, one day, the errors below appear and they prevent me from using the...
1
by: BigBaz | last post by:
If we have a graph G=(N,E), where N is the set of nodes, and E is the set of edges. If we partition N into k parts (partition 1, 2,3...k). And this partition is given by an array, with the node...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.