clear
z=sin(x)+cos(y)/x;
fsurf(z,[0.1 3 -6 8])
I want to depict this surface (z=sin(x)+cos(y)/x), but I can't because of it doesn't know x and y, what should I do?
x ∈ [0.1, 3], y ∈ [−6, 8]
Probably I should give an value to x and y, but I don't know how should I do.
Just add
x = 0.1:0.1:3.0 and y = -6.0:0.8.0
Related
I have a vector a with values
0.4000 0.4604
How to connect points with y value for instance 5 and x values of vector? I mean [0.4 0.46] using a vector and lets say y variable.
a
y = 5
one point is [0.4,5] and the second one [0.4604,5]
X = [0.4, 0.46];
Y = [5, 5];
plot(X, Y);
I have a time column vector
t =
[0;
1;
3;
7;
10]
a frequency column vector
f =
[978;
573;
269;
102;
14]
and an impedance column vector
Z =
[0;
10;
64;
97;
103]
The kind of surface plot I'm looking for would be so that if you rotate the figure to display Z vs. t, you would see something equivalent to
plot(t, Z)
and if you rotate the figure to display Z vs. f, you would see something equivalent to
semilogx(f, Z)
x axis time, y axis frequency, and z axis impedance.
Here's what I have so far:
Zimp1 = flipud(toeplitz(flip(Z)));
figure(1);
surf(t, f, Zimp1);
set(gca, 'Yscale', 'log');
The problem lies within the Zimp1 matrix--the matrix that shows what's going on in the surface plot with the values of frequency and time. How do I construct the Zimp1 matrix to give me exactly that: plot(t, Z) on the view([-90, 0]) side and semilogx(f, Z) on the view([0, 0]) side?
I am not a matlab user,I just want to rewrite a function from matlab to python.
So my question is excatly like in tittle,what is meaning of X(1,:) = [x y];
When X is array and x,y are vectors?
Suppose:
x = [1 2 3]
y = [4 5 6]
Then [x y] results in
[1 2 3 4 5 6]
So the two vectors are concatenated.
X(1,:) = ... assigns the right hand side to the first row of matrix X.
X(1,:) = means "put whatever's on the right into the 1st row of X".
[x y] means horizontal concatenation.
Note that if X exists in the workspace, the combination of x and y needs to be of the correct size, or else you'll get a Subscripted assignment dimension mismatch. error.
You can see an example in the answer of m.s.
I don't understand why the patch command fill with red the area above my function instead of the area below it; I mean the area between the graph of my function and the axis of abscissas.
x = linspace(0, 4);
f = x.^2;
plot(x, f)
patch(x, f, [1 0 0])
Because patch draws a closed polygon. And after your last point it goes back to the first on the shortest way. You need to add an additional points at the end and beginning with the last/first argument, but f = 0.
Like that:
x = linspace(0, 4);
f = x.^2;
plot(x, f)
%adjust data
x = [x(1) x x(end)];
f = [0 f 0];
patch(x, f, [1 0 0])
will give:
Or just use area as suggested by Luis Mendo:
area(x, f,'FaceColor',[1 0 0])
How can I draw i.e. x = 5 line in plot at Matlab?
I plot like that:
x = (-10:.1:10);
f= 10;
plot(x, f, 'r');
of course it doesn't work. For every variable of x, y is equal to 0 except for x=10. When x = 10 y equals to everything. How to plot this?
In MATLAB, plot(X, Y) simply draws points on the graph (and connects them with lines). Note that in this form of syntax, X and Y must have the same dimensions. Therefore, to plot the line x = 5 create a vector of your desired y-coordinates, and then create matching x-coordinates, which are all equal to 5:
Y = -10:0.1:10;
X = 5 * ones(size(Y));
plot(X, Y);
A useful function from the FileExchange in hline and vline.
You could also achieve this by plotting only 2 points:
f = 5;
plot([-10 10] , [1 1]*f);
I think using line is more straightforward here than plot.
x = [-10, 10];
f = ones(size(x));
f = 5 .* f;
line(x, f);