Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: how to make a user-defined matrix...???
Replies: 2   Last Post: Jun 3, 2012 12:57 AM

 Messages: [ Previous | Next ]
 Quynh Tram Nghuyen Thi Posts: 37 Registered: 4/13/12
how to make a user-defined matrix...???
Posted: Jun 2, 2012 9:14 PM

Good morning alll,
iam having a trouble to make a user-defined matrix. i dont know how to make a matrix by myself.
i ll give 2 samples of matrix-making frm my teacher:
1/ function [R,DR,D2R]=fdm(a,b,f,dx,n,x0,xn)
A=zeros(n-1);
B=zeros(n-1,1);
R=zeros(n+1,1);
DR=zeros(n+1,1);
D2R=zeros(n+1,1);
R(1)=x0;
R(n+1)=xn;
for i=1:n-1
if i==1
A(i,i)=2-b*dx^2/a;
A(i,i+1)=-1;
B(i)=-f(i+1)*dx^2/a+R(1);
elseif i==n-1
A(i,i-1)=-1;
A(i,i)=2-b*dx^2/a;
B(i)=-f(i+1)*dx^2/a+R(n+1);
else
A(i,i-1)=-1;
A(i,i)=2-b*dx^2/a;
A(i,i+1)=-1;
B(i)=-f(i+1)*dx^2/a;
ends
end
R(2:n)=inv(A)*B;
D2R=(f-b.*R)./a;
DR(1)=(R(2)-R(1)-D2R(1)*dx^2/2)/dx;
DR(n+1)=(R(n+1)-R(n)+D2R(n+1)*dx^2/2)/dx;
DR(2:n)=(R(3:n+1)-R(1:n-1))/(2*dx);

OR
2/ function [x,dx]=fdm1(a,b,f,h,n,x0,dx0)
x(:,1)=x0(:);
dx(:,1)=dx0(:);
for i=1:n
x(:,i+1)=h/a*f(i)+(1-b*h/a)*x(:,i);
dx(:,i+1)=(1/a)*f(i+1)-b/a*x(:,i+1);
end

they are soo complicated, arent they?? i dont understan where the syntaxes come.
please, i dlove to listen ideass.
iam waiting.
thankss

Date Subject Author
6/2/12 Quynh Tram Nghuyen Thi
6/2/12 ImageAnalyst
6/3/12 Nasser Abbasi