matlab write equation in MATLAB? -
i have data in x
, y
, , want solve the next equation using matlab. how can write matlab code equation ?
y= y1, ...,y(n-1),yn; x=x1,...x(n-1),xn
for example
c= 0.2345+5.423*y(n-1)*x(n-3)+2*y(n-5)*x(n-4)
ok, describing vector/matrix multiplication problem, can code as:
c0 = 0.2345; % first constant use in c n = 6; % sake of argument, assume n=6; m = [ 0 2 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 0 0 0 0; 0 0 5.423 0 0 0; 0 0 0 0 0 0]; c = c0 + y' * m * x;
i assuming both vectors, x
, y
column vectors. matlab notation says y'
transpose of vector y
, row vector.
when write c = c0 + y'*m*x
, (using pseudo-code)
c = c0 + sum(i=1:n)( sum(j=1:n)( m(i,j) * y(i) * x(j) ) )
please note approach allows store any factor multiplying y(i)*x(j)
in position m(i,j)
.
Comments
Post a Comment