473,396 Members | 1,935 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,396 software developers and data experts.

Equations ( polynomials ) multiplication

21
HI everybody,
I am trying to multiply the two polynomials shown below, A using C programming language, as you know this will lead to a convolution multiplication , which means that every single element of A must be multiplied by all elements of B .
A=1+2x+3x^2+4x^3+5x^4+6x^5
B=1+2x+3x^2
This leads to C= 18 x^7 + 27 x^6 + 28 x^5 + 22 x^4 + 16 x^3 + 10 x^2 + 4 x + 1
I have tried to do this using the following code, but did not work. I would be very pleased if you could kindly let me know how this can be done.


Expand|Select|Wrap|Line Numbers
  1. # include <stdio.h>
  2. # include <conio.h>
  3.  
  4. int main( void)
  5.  
  6. {
  7.     int i,j;
  8.    int na=100;   
  9.    double A[1][5]; 
  10.     double B[1][ 2];  
  11. double C[1][2+5]  // the resultant matrix 
  12.   A[1][0]=1;
  13. A[1][1]=2;
  14.  A[1][2]=3;
  15.   A[1][3]=4;
  16.  A[1][4]=5;
  17.   A[1][5]=6;
  18. B[1][0]=1.0;
  19.  B[1][1]=2.0;
  20.  B[1][2]=3.0;
  21.  
  22. for ( i=1;j<=3;j++)
  23.      {
  24.           for ( j=1;i<=6;i++)      
  25.       {  
  26.  
  27. C[i][j]=   A[i][j]*B[i][j];  
  28.  
  29.       printf(" \n C  %d", C[i][j]);   
  30.  
  31.       }
  32.  
  33.   }
Jun 6 '10 #1
7 5230
newb16
687 512MB
You use different variables in loop init and increment expressions
i=1;j<=3;j++)
, address C array outside its bounds (C[1][...] and c[i][j] where i>0 )
Are there any reasons for making A and B two-dimensional?
Jun 7 '10 #2
sheff
21
HI Newb16, thnx for ur reply.
regarding the increment expressions, I have corrected them, but forgot to do the same when I copied and pasted the code to this site. but still getting wrong answer .
there is no reason for the A, B being two dimensional, just though this how it can be done, any suggestions??
Jun 7 '10 #3
sheff
21
Newb16,

just to make life easy for you and everybody else who could help, lets assume you are given
A=1+2x+3x^2+4x^3+5x^4+6x^5
B=1+2x+3x^2
and you are asked to multiply them, how would you do that? and nice suggestions?
Jun 7 '10 #4
newb16
687 512MB
A,B - source polynomials, res - result.
in your example A={1,2,3,4,5,6}, B={1,2,3} Observing what power will a result of multiplying A[i] by B[j] -
foreach(i,j) res[i+j]+=A[i]*B[j];
Jun 7 '10 #5
weaknessforcats
9,208 Expert Mod 8TB
A=1+2x+3x^2+4x^3+5x^4+6x^5
B=1+2x+3x^2

Consider using an ordered array. That is, an array where element 0 is for x^0, element 1 for x^1 ,etc. That would give:

int A[10] = {1,2,3,4,5,6,0,0,0,0};
int B[10] = {1,2,3,0,0,0,0,0,0,0};
int C[10] = {0,0,0,0,0,0,0,0,0,0};

Then write a nested loop to multiply an element of A to every element of B. As you go, add the product to the array C in tghe correct element. That is, the product of element 4 of A multiplied by element 3 of array B will be added to element 7 of array C.

Be sure no products need to bed added outside the range of array C.

I used 10 above to simplify coding by having the arrays be the same size. You could define the array size at run time.
Jun 7 '10 #6
sheff
21
HI weaknessforcats, thank you for you response,

the idea you suggested sounds good to me but I am not sure if you considered the fact that addition needs to be carried out after we multiply each element of A by B, so if we place it stright away into C, then how we gonna do the addition of the numbers of similar polynominal degrees. e.g
when the element 1 from B is multiplied by the element 2x from A, the result is 2x this will be added to the result of multiplying the element 2x from B with the element 1 in A leading to 4x in the second element of C. I am not sure if the program you suggested considers that, if so, plse put some more illustrations.

A=1+2x+3x^2+4x^3+5x^4+6x^5
B=1+2x+3x^2
Jun 8 '10 #7
newb16
687 512MB
Yes, it was considered -

...That is, the product of element 4 of A multiplied by element 3 of array B will be added to element 7 of array C...

Note 'added' and 3+4 = 7.
Jun 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: smjmitchell | last post by:
Hi All, I need to display some equations on a form in VB (I will print the result in a text box beside the equation). The equations will in some cases be quite complicated and include...
3
by: Chris | last post by:
Does anyone know of a good standalone implementation of multivariable polynomials in python? Thanks, Chris
9
by: Ralf Hildebrandt | last post by:
Hi all! First of all: I am a C-newbie. I have noticed a "strange" behavior with the standart integer multiplication. The code is: void main(void)
8
by: vj | last post by:
Hi all, I want to solve the two equations u*tan(u)=w and u^2 + w^2=V^2, where V is a known constant, and u and w are the two unknowns to be determined. Please can someone suggest me how to...
2
by: DaRok28 | last post by:
// Program Description: // This program solves quadratic equations to find their roots. This // program takes values of a, b, and c as input and outputs the root(s). // The user can repeat the...
4
by: Matthias | last post by:
how do i make a program that gets numbers from a user. and then stores it into an array. using polynomials if the user entered 7 5 4 3 2 the polynomial would be 7x^4+5x^3+4x^2+3x+2 the program...
1
by: Motanyane Tlotliso | last post by:
I wish someone to help me in creating a programm in C++ that can be able to sum two polynomials, subtract one from the other and multiply both polynomials together using a ADT's(struct term). I...
4
by: sdufoo | last post by:
Hallo guys, I have to solve a system of Differential equations: http://picasaweb.google.de/sdufoo/EcuacionesDiferenciales02/photo#5228386949051570594 these are the equations of an induction...
1
by: HypeBeast McStreetwear | last post by:
Hello everyone. I got a assignment that states. The set of linear equations a11X1 = a12X2 = c1 a21X1 = a22X2 = c2 May be solved using Cramer’s rule: X1 = c1a22 – c2a12 a11a22 –...
6
by: awais888 | last post by:
i need a code to multiply two polynomials in galois field 2 in c# or c++, polynomials will be entered by user in integer (decimal values).
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.