# Thread: Help with my project

1. ## Help with my project

HI,
i m a mech engg student currently working on a project to develop a mathematical model of a 4 cylinder diesel engine.
the equation i m trying to solve in matlab is of the basic form

Tcombustion + Tfriction+ Tmass = 0

all the above parameters (T 's) are fuctions of the crank angle (y) and has sme 2nd order terms

so i separated the 2nd order terms, 1st order terms and finally constant and created a seperate m-file for each of it

1st term:

term1=0.036+5*symsum((0.06)*(sin(y)+((0.5*sin(y)*c os(y))/sqrt(1- 0.025*(sin(y))^2)))1,2);

2nd term:

term2=(symsum((0.06)*(sin(y)+((0.5*sin(y)*cos(y))/sqrt(1-0.025*(sin(y))^2))),1,2))*(5*(0.06*cos(y)+(0.03125 *(sin(2*y))^2)/(1-0.025*(sin(y))^2)-(0.5*cos(2*y))/(sqrt(1-0.025*(sin(y))^2)))*y^2+(0.0025*symsum((0.06)*(sin (y)+((0.5*sin(y)*cos(y))/sqrt(1-0.025*(sin(y))^2))),1,2)));

3rd term :

term3=symsum((p2*y-p1)*ap*((0.06)*(sin(y)+((0.5*sin(y)*cos(y))/sqrt(1-0.025*(sin(y))^2)))),1,2);

Well its actually a mess of a lot of terms in here

now i hav to solve the 2nd order ode of the form

Ay''+By'+Cy=0

where A, B and C are the above terms

now i wrote a separate m file for the function which is :

function dydt=ode1(t,x)
dydt=zeros(2,1);
dydt(1)=x(2);
dydt(2)=-b(x(2)) - c(x(1));

where
x=y'

i m getting errors and not able to solve
can u guys help me with this
i m not sure but do i need to separate the 'y' terms in the equation ????

2. Originally Posted by Shinchan
HI,
i m a mech engg student currently working on a project to develop a mathematical model of a 4 cylinder diesel engine.
the equation i m trying to solve in matlab is of the basic form

Tcombustion + Tfriction+ Tmass = 0

all the above parameters (T 's) are fuctions of the crank angle (y) and has sme 2nd order terms

so i separated the 2nd order terms, 1st order terms and finally constant and created a seperate m-file for each of it

1st term:

term1=0.036+5*symsum((0.06)*(sin(y)+((0.5*sin(y)*c os(y))/sqrt(1- 0.025*(sin(y))^2)))1,2);

2nd term:

term2=(symsum((0.06)*(sin(y)+((0.5*sin(y)*cos(y))/sqrt(1-0.025*(sin(y))^2))),1,2))*(5*(0.06*cos(y)+(0.03125 *(sin(2*y))^2)/(1-0.025*(sin(y))^2)-(0.5*cos(2*y))/(sqrt(1-0.025*(sin(y))^2)))*y^2+(0.0025*symsum((0.06)*(sin (y)+((0.5*sin(y)*cos(y))/sqrt(1-0.025*(sin(y))^2))),1,2)));

3rd term :

term3=symsum((p2*y-p1)*ap*((0.06)*(sin(y)+((0.5*sin(y)*cos(y))/sqrt(1-0.025*(sin(y))^2)))),1,2);

Well its actually a mess of a lot of terms in here

now i hav to solve the 2nd order ode of the form

Ay''+By'+Cy=0

where A, B and C are the above terms

now i wrote a separate m file for the function which is :

function dydt=ode1(t,x)
dydt=zeros(2,1);
dydt(1)=x(2);
dydt(2)=-b(x(2)) - c(x(1));

where
x=y'

i m getting errors and not able to solve
can u guys help me with this
i m not sure but do i need to separate the 'y' terms in the equation ????
Well first of all I would not use symsum for the terms, but define them as matlab functions, assuming you are using matlab.

CB

3. Originally Posted by CaptainBlack
Well first of all I would not use symsum for the terms, but define them as matlab functions, assuming you are using matlab.

CB
I m not able to solve it as i m new to matlab

4. Originally Posted by Shinchan
so can u help me simplify it....bcoz m a newbie in matlab
I'm sorry but I cannot understand what you have posted, can you try some thing closer to English?

CB

5. Originally Posted by CaptainBlack
I'm sorry but I cannot understand what you have posted, can you try some thing closer to English?

CB
Well let's remove the symsum function
the error i m getting here is that the variable x(2) is being recognised as afunction in matlab
hence it doesn't solve the function quoting that function x is not defined

6. Originally Posted by Shinchan
Well let's remove the symsum function
the error i m getting here is that the variable x(2) is being recognised as afunction in matlab
hence it doesn't solve the function quoting that function x is not defined
First of all ask yourself what are a, b, and c in the derivative function?

Are they scalars? If so the code is wrong because you are using them like functions of arrays.

Are they functions? If so how does your code know this?

In fact the function has no way of knowing what they are at all.

CB

7. Originally Posted by Shinchan

term1=0.036+5*symsum((0.06)*(sin(y)+((0.5*sin(y)*c os(y))/sqrt(1- 0.025*(sin(y))^2))),1,2);
I'm sorry to go back to these expressions, but there seems to be some ambiguity here in what the A, B and C are in your ODE. The expression above would if correct be a numeric constant, as symsum preforms a symbolic summation over whatever variable the automatic variable identification algorithm decides is the index of summation. In this case the variable of summation would be "y".

This makes no sense to me, I expect the A, B and C to be either constants or functions of the independent variable (and for A and B possibly the dependent variable).

It would help if you could tell us what the coefficients are meant to be in some notation other than Matlab code. My suspicion is that these are functions and would be best declared as subfunctions of your derivatives function.

CB

8. Originally Posted by CaptainBlack
I'm sorry to go back to these expressions, but there seems to be some ambiguity here in what the A, B and C are in your ODE. The expression above would if correct be a numeric constant, as symsum preforms a symbolic summation over whatever variable the automatic variable identification algorithm decides is the index of summation. In this case the variable of summation would be "y".

This makes no sense to me, I expect the A, B and C to be either constants or functions of the independent variable (and for A and B possibly the dependent variable).

It would help if you could tell us what the coefficients are meant to be in some notation other than Matlab code. My suspicion is that these are functions and would be best declared as subfunctions of your derivatives function.

CB
Ahh, i got your point. i made a mistake that i declared the constants A, B and C as functions of y (which is wrong, they must be constants)
so now i need to separate the constant terms from 'y' terms (ie sin(y) and cos (y) should be separated).
Thanks.

9. I tried to simplify my problem so i calculated values of some constant terms and the tried to solve the 2nd order ODE but i got following problems.......

Constant values previously calculated...
Tf
Tc
djdy

M-file: (for ODE)

function dxdy = ode (t,x)
dxdt = zeros (2,1);
dxdt(1) = Tf .* x(1) - djdy .* x(1) + Tc ;
dxdt(2) = x(2);

command :

[t x] = ode45( @ode , [1 : 0.5 : 10] , 0)

Errors:

Warning: Could not find an exact (case-sensitive) match for 'Tf'. F:\Matlab\toolbox\control\control\@tf\tf.m is a case-insensitive match and will be used instead. You can improve the performance of your code by using exact name matches and we therefore recommend that you update your usage accordingly. Alternatively, you can disable this warning using warning('off','MATLAB:dispatcher:InexactMatch').
> In ode at 3
In funfun\private\odearguments at 110
In ode45 at 173
??? Function 'times' is not defined for values of class 'tf'.

Error in ==> times at 18
[varargout{1:nargout}] = builtin('times', varargin{:});

Error in ==> ode at 3
dxdt(1) = Tf .* x(1) - djdy .* x(1) + Tc ;

Error in ==> funfun\private\odearguments at 110
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.

Error in ==> ode45 at 173
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, ...