Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.