How to plot x(i+1,j+1) with respect to i,j from the given data ,code shown in the body?

2 次查看(过去 30 天)
clc;
close all;
clear all;
A1=[0 -.75;-1 0];
A2=[.27 0;0 0];
A3=[0 -.001;0 0];
x(1,1)=1
x(1,2)=2
x(2,1)=1
for i=1:2
for j=1
z=x(i+1,j+1)==A1.*x(i,j+1)+A2.*x(i+1,j)+A3.*x(i,j)
end
end
[i,j]=meshgrid(2:3,2)
surf(i,j,z)
[EDITED, Jan, please format your code]
  4 个评论
Abhay
Abhay 2014-10-12
The problem is as follows: x(i+1,j+1)=A1*x(i,j+1)+A2*x(i+1,j)+A3*x(i,j) where x(i+1,j+1),x(i,j+1) and x(i+1,j) and x(i,j) , is a state vector of 2x1 dimension and A1,A2 and A3 are constant system matrices of 2x2 dimension, initial conditions is x(1,1)=1;x(1,2)=2;x(2,1)=1 Problem is to plot x(i+1,j+1) with respect to i and j. Values of A1=[0 -.75;-1 0] , A2=[.27 0;0 0], A3=[0 -.001;0 0]
Sir the code which I had tried is not working.

请先登录,再进行评论。

采纳的回答

SK
SK 2014-10-12
Hi Abhay,
The problem as you as you have stated it is under-determined. What you additionally need are boundary conditions. For example if you knew the boundary values:
x(1, j) for all j
and
x(i, 1) for all i
Then you could easily generate all the values. Maybe you need to assume that the boundaries are zero?
Also since this is a 2-D to 2-D function, how do you plan to visualize it in a plot?
By the way, to type code, just start the code line with two spaces.
  10 个评论
SK
SK 2014-10-15
编辑:SK 2014-10-15
If you look at the documentation for the surf() funstion in Matlab, you will see that you are using 2 different functions:
surf([X1; X2])
Here you have written [X1; X2] - which is a single matrix formed by concatenating X1 and X2 vertically. Similarly in
surf([X1, X2])
[X1, X2] is also a single matrix formed by concatenating X1 and X2 horizontally.
So in both these you are using the 1-argument form of surf where the (x y) grid is taken to be (1:n) x (1:n). But because [X1; X2] is a different matrix from [X1, X2], the result is different
On the other hand in:
surf(X1, X2)
the first argument is X1 and the second X2. You are using the two argument form of surf(). The second argument specifies only the color shading. So you are only plotting X1.
X is a 2 x N x N matrix, so when you reshape, the result should also have 2*N*N elements. But in your reshape() line it has only N*N elements. For example you could reshape as:
reshape(X, [2*N, N]).
But be very careful when you reshape. In fact the above command is probably not what you want because of the order in which the elements are placed. When Matlab reshapes, it takes the elements, counting along each dimension starting from the first in turn. You have to reshape in such a way that your elements don't get mixed up. In your case you may need to use the permute() function before you reshape.
_________
In addition, let me offer you some unsolicited advice. If you are planning to use Matlab for at least some period of time for your work, it would be worth it to invest some of your time learning the basic syntax and getting familiar with it. It is not exactly my favorite language, but it is very widely used and is relatively easy to learn.
You could start by going to:
The suggested exercises there can help you get comfortable with with Matlab syntax. Then you would not be so dependent on others for these basic language issues. There are also a lot of online tutorials and short documents that give you information about Matlab. Of course you need to be willing to invest some time experimenting with it.
Abhay
Abhay 2014-10-16
Dear sir, Thanks for the clarification and your kind advice. Now if will try to tune myself more towards, in learning the cody which in my opinion is the base of this matlab programme, thanks for providing a link for cody,as a beginner it helps me a lot.
With Thanks and Regards, Abhay

请先登录,再进行评论。

更多回答(2 个)

Abhay
Abhay 2014-10-12
{clc; clear all; }

Abhay
Abhay 2014-10-15
Dear all; Regarding my earlier question of 3D plot of 2-D discrete system which was wonderfully solved by SK, I had posted one query,Kindly put your expert comment over that.Thanks
  1 个评论
Abhay
Abhay 2014-10-15
Dear all; Regarding my earlier question of 3D plot of 2-D discrete system which was wonderfully solved by SK, I had posted one query,Kindly put your expert comment over that.Thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by