mirror of https://github.com/Askill/AP-SCE.git
parent
9a2d6028b4
commit
9254b68273
|
|
@ -0,0 +1,59 @@
|
|||
#include "mex.h"
|
||||
#include "matrix.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
|
||||
|
||||
void mexFunction(int nlhs, mxArray *plhs[], // Output
|
||||
int nrhs, const mxArray *prhs[]) // Input
|
||||
{
|
||||
/*
|
||||
char *func_Name;
|
||||
func_Name = mxArrayToString(prhs[0]);
|
||||
double* tout = mxGetPr(prhs[4]);
|
||||
double* xout = mxGetPr(prhs[5]);*/
|
||||
|
||||
double t0 = *mxGetPr(prhs[0]);
|
||||
double tfinal= *mxGetPr(prhs[1]);
|
||||
double x0 = *mxGetPr(prhs[2]);
|
||||
|
||||
double theta_umg = 20, //temp of room
|
||||
theta = x0, //start temp
|
||||
h = 1, //incremtens size
|
||||
t_start = t0, //start time
|
||||
t_end = tfinal, //end time
|
||||
t=t_start,
|
||||
theta_dot = 0;
|
||||
|
||||
int len = (t_end-t_start)/h+1;
|
||||
double* t_out = (double *)mxCalloc(len, sizeof(double)); //array cont. time stamps
|
||||
double* theta_out = (double *)mxCalloc(len, sizeof(double)); //array cont. temp
|
||||
|
||||
|
||||
t_out[0]=t_start;
|
||||
theta_out[0]=theta;
|
||||
|
||||
for(int i = 1; t<t_end; i++)
|
||||
{
|
||||
theta_dot = -1*(theta-theta_umg)/2; //<- totally different from (-1/2)*(theta-theta_umg), because that doesn't work!
|
||||
theta += theta_dot*h;
|
||||
//debug output mexPrintf("%f \t %f \t %f \t %f\n",theta_dot, theta, theta_umg,h);
|
||||
t += h;
|
||||
t_out[i] = t;
|
||||
theta_out[i]= theta;
|
||||
}
|
||||
|
||||
|
||||
// Output
|
||||
nlhs = 2;
|
||||
|
||||
plhs[0] = mxCreateDoubleMatrix(1, len, mxREAL);
|
||||
memcpy(mxGetPr(plhs[0]), t_out, len*sizeof(double));
|
||||
|
||||
plhs[1] = mxCreateDoubleMatrix(1, len, mxREAL);
|
||||
memcpy(mxGetPr(plhs[1]), theta_out, len*sizeof(double));
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
% function accepts 3 doubles
|
||||
% a700(to, t_end, x0)
|
||||
%
|
||||
% a700 simulates the cooling of a fluid
|
||||
%
|
||||
%exp.: [a1,a2]=a700(0,10,100)
|
||||
% a1 = 0 1 2 3 4 5 6 7 8 9 10
|
||||
% a2 = 100.000 60.000 40.000 30.000 25.000 22.500 21.250 20.625 20.312 20.156 20.078
|
||||
Loading…
Reference in New Issue