Hello my code below is returning the wrong value when the MatrixMult function is called in StateEstimate for the value M2. When the code is debugged, with a break point at void MatrixMult() and i step through, M2 returns only the first line of A {1, 0, 0, T, 0, 0} where it should return the complete array which i believe is the reason why x gives out garbage and segmentation error at the end instead of {0,0,0,5,10,5}?
Any help would be gratefully aprreciated. - #include <stdio.h>
-
#include <stdlib.h>
-
#include <math.h>
-
#define T 10
-
/*********** global variables which remain constant ****/
-
static double A[6][6] = {{1, 0, 0, T, 0, 0}, {0, 1, 0, 0, T, 0}, {0, 0, 1, 0, 0, T}, {0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1}};
-
static double B[6][6] = {{50, 0, 0, 0, 0, 0}, {0, 50, 0, 0, 0, 0}, {0, 0, 50, 0, 0, 0}, {10, 0, 0, 0, 0, 0}, {0, 10, 0, 0, 0, 0}, {0, 0, 10, 0, 0, 0}};
-
static double U[1][6] = {0, -9.81, 0, 0, 0, 0 };
-
-
/************* matrix multiplication function **********/
-
-
void MatrixMult(double M1[][6], double M2[][6], double M3[][6],int m, int n)
-
{
-
-
int i, j, k;
-
-
for(i=0;i<m;i++)
-
for(j=0;j<m;j++)
-
{ M3[i][j]=0;
-
for(k=0;k<n;k++)
-
M3[i][j] = M3[i][j]+M1[i][k]*M2[k][j];
-
}
-
}
-
/************** vector addition funciton **************/
-
void VectAdd(double M1[1][6],double M2[1][6], double M3[1][6],int m, int n)
-
{
-
int i,j,k;
-
for(i=0;i<m;i++)
-
{
-
for(j=0;j<n;j++)
-
M3[i][j]= M1[i][j] + M2[i][j];
-
}
-
}
-
/*********** predicted state equation x = A*xi + B*U ******/
-
double StateEstimate(double x[][6])
-
{
-
int i,j,k;
-
double ax [1][6];
-
double bu [1][6];
-
-
MatrixMult(x, A, ax,6,6);
-
MatrixMult (U,B,bu,1,6);
-
VectAdd(ax,bu,x,1,6);
-
-
for(i=0;i<6;i++)
-
{
-
printf("\n");
-
for(j=0;j<6;j++)
-
{
-
printf(" x[%d][%d]= %.2f" ,i,j, x[i][j]);
-
}
-
}
-
printf("\n \n");
-
}
-
/******************* Main Function *********************/
-
int main(void)
-
{
-
int i,j;
-
double x[1][6] = {0, 0, 0,5, 10, 5};
-
-
StateEstimate(x);
-
}
Sorry also forgot to mention that at
MatrixMult(x, A, ax,6,6);
this should be
MatrixMult(x, A, ax,1,6);
There are two problems that I see off the top, from just looking at your code: - In MatrixMult, lines 17 and 18, you use the same limit variable, m, for both loops.
- In StateEstimate, line 50, your program should start printing garbage in the second pass through the i loop (i = 1).
Cheers!
Oralloy
3 1799
There are two problems that I see off the top, from just looking at your code: - In MatrixMult, lines 17 and 18, you use the same limit variable, m, for both loops.
- In StateEstimate, line 50, your program should start printing garbage in the second pass through the i loop (i = 1).
Cheers!
Oralloy
okay i understand what you mean about the first prroblem but not sure on;
In StateEstimate, line 50, your program should start printing garbage in the second pass through the i loop (i = 1).
Ta.
Chris,
Well, the line 50 loop runs across six array rows. The array you're sending to the function StateEstimate only has one row (your array x at line 59). The remaining five row displays will pick up garbage from the stack.
Luck!
Oralloy
Sign in to post your reply or Sign up for a free account.
Similar topics
by: learning_C++ |
last post by:
I hope to use template. in my code I hope to sum the vector<int> and
vector<double>. But there are several errors:
sumtemplate.cpp:6: error: ISO C++ forbids declaration of `sum' with no
type...
|
by: christopher diggins |
last post by:
Here is some code I wrote for Matrix multiplication for arbitrary
dimensionality known at compile-time. I am curious how practical it is. For
instance, is it common to know the dimensionality of...
|
by: eight02645999 |
last post by:
hi
i use odbc to update a table in a database but i always get return
value of -1
even though i tried to return an integer. the table is updated though
....
sql = """
update table
set column =...
|
by: Hardy Wang |
last post by:
Hi all,
I have the following codes, but SCOPE_IDENTITY() just returns NULL to
me. If I comment out SCOPE_IDENTITY() line and run @@IDENTITY line, it works
fine!! Since I have a trigger on the...
|
by: Klaas Vantournhout |
last post by:
Hi all,
I'm in need of a matrix of function pointers, and to be honest. No
'nice' solution has been found yet on that big big internet.
It is possible to declare a matrix of function pointers...
|
by: moondaddy |
last post by:
I'm working with c# 3.0 and am wondering if I can make a class return a
value like a function. For example, I would like to do something like this:
Point pt;
pt=SomeClass someclass=new...
|
by: ELINTPimp |
last post by:
Hello all,
Have a really interesting problem (at least to me) with my
upload_file() function. I have it working now, with a bit of a work
around, but would like to know what everyone thinks in...
|
by: Terry Olsen |
last post by:
How do I get this to work? It always returns False, even though I can see
"This is True!" in the debug window. Do I have to invoke functions
differently than subs?
Private Delegate Function...
|
by: shanfeng |
last post by:
such as a function: f(double v, int a)
could this function return both a integer and array?
Thank you very much. I have confused on this for a long time~
|
by: raras |
last post by:
could somebody help me to write the script of program to multiply 2D matrix using function and pointer? please ... thanx for helping me!
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |