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
回答(2 个)
Matt Tearle
2011-3-23
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
2011-3-23
0 个投票
1 个评论
Matt Tearle
2011-3-23
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!