Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Ed Nowak
Posts:
8
From:
Southern California
Registered:
3/3/13


Re: difference equation
Posted:
Mar 3, 2013 4:10 AM


> "vikas kumar" wrote in message > <icqlsr$7mp$1@fred.mathworks.com>... > > how do we solve this difference equation : > > y(n) + 1/2y(n1) + 3/4y(n2) = x(n) > > > > where x(n)=(1/4)^n for all n>0 > > & y(1)=4 , y(2)=6 > > use this program > % This Matlab program implements the general > difference equation, > > % a0y(n) = b0x(n) + b1x(n1) + b2x(n2) + ...+ bM > x(nM) > % a1y(n1)  a2y(n2)  ... aN y(nN) > > disp(' Implementation of general difference > equation'); disp(' '); > b = input('Enter the x coefficients b = '); > a = input('Enter the y coefficients a = '); > x1 = input('enter the input samples x = '); > int = input('enter the intial values int = '); > y= int; > lint=length(int); > x=[zeros(1,lint) x1]; > n=length(x); > lb=length(b); > la=length(a); > for s= (lint+1):length(x) > sumx=0; > sumy=0; > for j=2:(la) > sumy=sumy+a(j)*y(sj+1); > end > for f=1:lb > sumx=sumx+b(f)*x(sf+1); > end > y(s)=sumxsumy; > end > > disp('The output sequence is y(n) = '); > disp(y); > stem(y); > xlabel('samples n'); > ylabel('y(n)'); > grid on; > title('Implementation of difference equation'); > > > put y coefficient as a vector from the left side and > x coefficient as a vector too from the right side > and define the input vector on how many steps you > want it before running the program so as to use it > in input vector > put the initial values y(2) and y(1) > and you can see the solution
Hi Ali, I responded to your program (I named it "differenceEqSolve.m") as follows:
Implementation of general difference equation Enter the x coefficients b = {1} Enter the y coefficients a = { 1 0.5 0.75} enter the input samples x = 10 enter the initial values int = {0 4 6}
and I get the following error message:
Undefined function 'mtimes' for input arguments of type 'cell'. Error in differenceEqSolve (line 21) sumy=sumy+a(j)*y(sj+1);
What have I done wrong?



