How to plot x(i+1,j+1) with respect to i,j from the given data ,code shown in the body?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
SK
il 12 Ott 2014
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 Commenti
SK
il 15 Ott 2014
Modificato: SK
il 15 Ott 2014
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.
Più risposte (2)
Vedere anche
Categorie
Scopri di più su Surface and Mesh Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!