Inner matrix dimensions must agree HELP

x= 0:(pi/90):(pi/2);
o=sqrt(2)*(sqrt((1/pi)*(2+x.^2)-(1-((2*x)/pi))*((sin((pi/4)-(x/2)))).^2/((pi/4)-(x/2))));
plot (x,i)
I need to plot this but it is giving me the error "mtimes Inner matrix dimensions must agree". Any help on how I can fix this
also can anyone help me on how to do sin^2(x) in matlab? I have searched but with no sure answer I have tried to use the trigonometric identity (1-cos(2x))/2 but can anyone help me on how to do it without the identity

Answers (2)

In the middle of that line you have
(1-((2*x)/pi))*((sin((pi/4)-(x/2)))).^2
That should be an array multiply (.*), not a matrix multiply.
Also, your plot command should be plot(x,o), not i. I assume that's just a typo in your question.
Jose
Jose on 23 Mar 2011
yes it was a typo well yes thank you, I saw that was my problem
well now through editing I've come up with
x= 0:(pi/90):(pi/2);
o=sqrt(2)*sqrt(((1/pi)*(2+x.^2)-(1-((2*x)/pi)).*((sin((pi/4)-(x/2))).^2)/((pi/4)-(x/2))));
plot (x,o)
Problems: 1. How can I display degrees instead of radians on my plot?
2. So the plot should look like: a curve starting at 0 and ending around 1.8 ( http://www.algebra.com/cgi-bin/plot-formula.mpl?expression=graph(300%2C300%2C-2%2C8%2C-5%2C5%2C0%2C2*ln(x-1)%2C+(exp(x-4))-2)&x=0003 it should curve like the green line (ignore the axis) but it actually looks like the blue curve

1 Comment

1. Please start new questions for, well, new questions. Use the comments for follow-up discussion *about the same MATLAB topic*
2. plot(180*x/pi,o)
3. Looking closer, I notice that there's also a division by x (sin^2(...)/(pi/4-x/2). That should also be an array divide (./).
4. But overall, you should play with the algebra a bit before force-feeding it to MATLAB. You can simplify this expression such that you don't even need that divide.

Sign in to comment.

Categories

Asked:

on 23 Mar 2011

Community Treasure Hunt

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

Start Hunting!