From 9a2d6028b4c415715bb50b4befe4b70da0db7b6c Mon Sep 17 00:00:00 2001 From: Patrice Matz Date: Thu, 18 Jan 2018 15:22:20 +0100 Subject: [PATCH] - fixed a4.1.1, a4.1.2 and a542 now handels inputs --- Mex/a411.cpp | 103 +++++++++++++++++-------------------- Mex/a412.cpp | 142 ++++++++++++++++++++------------------------------- Mex/a542.cpp | 34 ++++++++---- Mex/a542.m | 11 ++++ 4 files changed, 135 insertions(+), 155 deletions(-) create mode 100644 Mex/a542.m diff --git a/Mex/a411.cpp b/Mex/a411.cpp index b85eb34..404858b 100644 --- a/Mex/a411.cpp +++ b/Mex/a411.cpp @@ -7,103 +7,94 @@ void mexFunction(int nlhs, mxArray *plhs[], // Output variables int nrhs, const mxArray *prhs[]) // Input variables { int variables = *mxGetPr(prhs[0]); + double inc = *mxGetPr(prhs[1]); double* x = (double *)mxCalloc(variables, sizeof(double)); //create solution array - double* xx = (double *)mxCalloc(variables, sizeof(double)); - double* yy = (double *)mxCalloc(variables, sizeof(double)); + double* x_in = (double *)mxCalloc(variables, sizeof(double)); //input x + double* y = (double *)mxCalloc(variables, sizeof(double)); //input y - double** GA = (double **)mxCalloc(variables+1, sizeof(double*)); //create Gauss Array (GA) + double** GA = (double **)mxCalloc(variables+1, sizeof(double*)); //create Gauss Array (GA) for (int i = 0; i <= variables; i++){ GA[i] = (double *)mxCalloc(variables+1, sizeof(double)); } for(int i=0;i= 0; i--) //back-substitution + for (int i = variables - 1; i >= 0; i--) //back-substitution { //x is an array whose values correspond to the values of x,y,z.. x[i] = GA[i][variables]; //make the variable to be calculated equal to the rhs of the last equation - for (j = i + 1; j= x[i] && xx[j] <= x[i + 1]) + { + // Interpolationsformel + yy[j] = ((y[i + 1] - y[i]) / (x[i + 1] - x[i])) * (xx[j] - x[i]) + y[i]; + } + else if (xx[j] > x[i + 1]) + { + savepoint = j; + break; + } } + } +//Code von Marvin Lehmann ende - for (i = variables - 1; i >= 0; i--) //back-substitution - { //x is an array whose values correspond to the values of x,y,z.. - x[i] = GA[i][variables]; //make the variable to be calculated equal to the rhs of the last equation - for (j = i + 1; j z) { @@ -55,6 +67,6 @@ int i; plhs[0] = mxCreateDoubleScalar(x); plhs[1] = mxCreateDoubleScalar(y); plhs[2] = mxCreateDoubleScalar(z); - plhs[3] = mxCreateDoubleScalar(i); + return; } \ No newline at end of file diff --git a/Mex/a542.m b/Mex/a542.m new file mode 100644 index 0000000..2cd07a7 --- /dev/null +++ b/Mex/a542.m @@ -0,0 +1,11 @@ +%function accepts 1 string, 2 double and increments +% a542("func_name", x, y, inc) +% function returns lowest found return of passed function +% +%exp.: +% function z=func(x,y) +% z=-(x*x + y*y); +% end +% +% a542("func",-2,-2, 0.1) +% ans=6.3838e-016 \ No newline at end of file