I’m new to MATLAB and I am having the following difficulty: I would like to have a graph of a function plotted but I keep getting the error that “Matrix dimensions must agree.”
The code I am using is as follows:
x = -1.5:0.1:1.5;
y = 1/sqrt(9 - x.^2) + 1/sqrt(4 - x.^2) - 1;
plot(x, y);
The error as it appears in the command window is:
Error using /
Matrix dimensions must agree.
Possibly the problem lies where I define x = -1.5:0.1:1.5; which makes MATLAB thinks this is a matrix, but all I want to do is have function values plotted at intervals of 0.1 between -1.5 and 1.5.
How can I get around this problem?
Operations like multiplication or division can have special meaning for matrices. If you’re interested in “normal”, element-wise operations, you need to use the dot before the operator, i.e.