Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8896349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:01:22+00:00 2026-06-15T00:01:22+00:00

I am trying to do complex vector addition and dot product using structures in

  • 0

I am trying to do complex vector addition and dot product using structures in C for a project. I have my code written, however, while it is compiling without a problem, once i run my program it stops working. I have other parts to the program but this is only the relevant part. I am also trying to do matrix addition and multiplication with complex numbers. I think I can modify the others if I can get these working. Any help at all would be appreciated. Thanks, I appreciate it.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define PI 3.14159265359

typedef struct complex
{
    double re;
    double im;
}complex;

typedef struct vect_complex
{
    double *re;
    double *im;
}vect_complex;

typedef struct mat_complex
{
    //int i=0,j=0;
    double re[100][100];
    double im[100][100];
}mat_complex;

void vector_add(vect_complex a[4], vect_complex b[4], vect_complex c[4])
{
    int i;
    for(i=0; i<3 ;i++);
    {
        c->re[i] = a->re[i] + b->re[i];
        c->im[i] = a->im[i] + b->im[i];
    }
    printf("Vector addition = (%f + %f*j)i + (%f +%f*j)j + (%f + %f*j)k\n\n",c-    >re[0],c->im[0],c->re[1],c->im[1],c->re[2],c->im[2]);
}

void addmx(mat_complex *a, mat_complex *b, mat_complex *c)
{
    int  i, j;
    for ( i = 0 ; i < '\0' ; i++ )
    {
        for ( j = 0 ; j < '\0' ; j++ )
        {
            c->re[i][j] = a->re[i][j] + b->re[i][j];
            c->im[i][j] = a->im[i][j] + b->im[i][j];
        }
    }
    printf("***Matrix Addition***\n");
    for ( i = 0 ; i < '\0' ; i++ )
    {
        for ( j = 0 ; j < '\0' ; j++ )
        {
            printf("(%f + %f*j)   ", c->re[i][j],c->im[i][j]);
        }
        printf("\n");
    }
}

int main()
{
vect_complex aaa;
vect_complex bbb;
*aaa.re = 5;
*aaa.im = 4;
*bbb.re = 3;
*bbb.im = 2;
vect_complex ccc;

vector_add(&aaa, &bbb, &ccc);
vector_dot_prod(&aaa, &bbb, &ccc);

return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:01:23+00:00Added an answer on June 15, 2026 at 12:01 am

    There are a number of issues to deal with here.

    1. vect_complex

    Perhaps you’d like your vect_complex to hold a fixed number of elements, in which case it should be defined:

    typedef struct vect_complex
    {
        double re[3];
        double im[3];
    } vect_complex;
    

    Alternatively, you can keep your current definition but you will need to allocate new arrays every time you use the structure:

    int main(void)
    {
        vect_complex vc;
    
        vc.re = (double *) malloc(3 * sizeof(double));
        vc.im = (double *) malloc(3 * sizeof(double));
    
        vc.re[0] = 1.0;
        vc.im[0] = 2.0;
        ...
    }
    

    2. vector_add

    This function should be taking references to vect_complex as inputs, not arrays of complex vectors. This implementation assumes the definition of vect_complex I gave above.

    void vector_add(vect_complex * a, vect_complex * b, vect_complex * result)
    {
        int i;
        for (i = 0; i < 3; i++)
        {
            result->re[i] = a->re[i] + b->re[i];
            result->im[i] = a->im[i] + b->im[i];
        }
    }
    

    3. addmx

    I’m not sure what the '\0's are doing here. Change it to

    for (i = 0; i < 100; i++)
        for (j = 0; j < 100; j++)
        {
            ...
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to send a complex type between two systems that have the same code
I am trying to render a complex XML document as webpage(FF only) using a
I'm have a fair complex Form that I am trying to create in Play
I have an interesting problem trying to represent complex schedule data in a database.
I am trying to use templates along with vector in my code the following
I am trying to visualize a rather complex structure in the dot language. Because
I am trying to get a vector to store objects of class 'Complex'. This
I'm trying to perform a complex issue, I have a query structured like this:
I am trying to render a very complex model using json file. The size
While trying to tackle a more complex problem, I came to compare access speed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.