Plots of functions involving quadratic denomonator

1 次查看(过去 30 天)
I am having great trouble with a plot I think should be very simple. I want to plot the following:
x=[0:1:100]; y=6-400/(100+x.^2);
My first stab at google lead me to the x. trick, but strangely it seems to fail if I have a quadratic expression in the denominator. I assume this is a syntax problem. If I try to enter the second line above, I get the following error:
??? Error using ==> mldivide Matrix dimensions must agree.
I understand that x is a matrix, but how come it works when this term is in the numerator instead?
I appreciate any help you can give on this. Thanks for reading.

采纳的回答

Jarrod Rivituso
Jarrod Rivituso 2011-4-4
The "x trick" you are using is actually the element-wise exponentiation. MATLAB is inherently a matrix language (MATrix LABoratory) and by default it wants to do matrix computations.
So, the reason for your error is that you need to be using element-wise division too. Again, use the . to make it element-wise.
>> y = 6 - 400./(100+x.^2)
The reason it worked when x was in the numerator is because dividing or multiplying by a scalar is a special case that MATLAB makes an exception for.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by