<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.de/matlabcentral/newsreader/view_thread/297396</link>
    <title>MATLAB Central Newsreader - Simple problem</title>
    <description>Feed for thread: Simple problem</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.de/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Fri, 26 Nov 2010 04:25:04 +0000</pubDate>
      <title>Simple problem</title>
      <link>http://www.mathworks.de/matlabcentral/newsreader/view_thread/297396#799441</link>
      <author>Andreas </author>
      <description>Hello, i have a simple problem. I say  that xd(1)=u*cos(theta) but in the output it is taken as zero! What i'm doing wrong? My code is below and at the end is the output! Thanks&lt;br&gt;
&lt;br&gt;
function [ ] = ntarki( theta, tInc )&lt;br&gt;
&lt;br&gt;
x(1)=0;&lt;br&gt;
y(1)=0;&lt;br&gt;
t(1)=0;&lt;br&gt;
d=1.2;&lt;br&gt;
m=600;&lt;br&gt;
u=900;&lt;br&gt;
g=9.81;&lt;br&gt;
i=1;&lt;br&gt;
xd(1)=u*cos(theta)&lt;br&gt;
yd(1)=u*sin(theta)&lt;br&gt;
&lt;br&gt;
while t(i)&amp;lt;30&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if t(i)&amp;lt;15&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a = 0.25;     &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cd = 0.38;    &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;a = 1.1;        &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cd = 0.9;     &lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;end&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&lt;br&gt;
Ax(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2));&lt;br&gt;
Ay(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2)+m*g);&lt;br&gt;
Bitax(i)=(tInc/2)*(xd(i)+Ax(i)/2);&lt;br&gt;
Bitay(i)=(tInc/2)*(yd(i)+Ay(i)/2);&lt;br&gt;
Bx(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2));&lt;br&gt;
By(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2)+m*g);&lt;br&gt;
Cx(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2));&lt;br&gt;
Cy(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2)+m*g);&lt;br&gt;
Deltax(i) = (tInc)*(xd(i)+Cx(i));&lt;br&gt;
Deltay(i) = (tInc)*(yd(i)+Cy(i));&lt;br&gt;
Dx(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i))^2);&lt;br&gt;
Dy(i) = (tInc/2)*(-1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i))^2+m*g);&lt;br&gt;
&lt;br&gt;
x(i+1)= x(i)+tInc*(xd(i)+1/3*(Ax(i)+Bx(i)+Cx(i)));&lt;br&gt;
xd(i+1)=xd(i)+1/3*(Ax(i)+2*Bx(i)+2*Cx(i)+Dx(i));&lt;br&gt;
&lt;br&gt;
y(i+1)=y(i)+tInc*(yd(i)+1/3*(Ay(i)+By(i)+Cy(i)));&lt;br&gt;
yd(i+1)=yd(i)+1/3*(Ay(i)+2*By(i)+2*Cy(i)+Dy(i));&lt;br&gt;
&lt;br&gt;
xdd(i) = -(1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2));&lt;br&gt;
ydd(i) = -(1/m)*(0.5*d*a*cd*(yd(i)^2+xd(i)^2)+m*g);&lt;br&gt;
&lt;br&gt;
t(i+1)=t(i)+tInc;&lt;br&gt;
&lt;br&gt;
i=i+1;&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
end&lt;br&gt;
&lt;br&gt;
----------------------------------------------------------------------------------------------------&lt;br&gt;
&lt;br&gt;
#&lt;br&gt;
///////OUTPUT FOR  ntarki(0.3,0.1)&lt;br&gt;
&lt;br&gt;
xd = 859.8028&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
yd =  265.9682&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&lt;br&gt;
&lt;br&gt;
yd =&lt;br&gt;
&amp;nbsp;&amp;nbsp;1.0e+127 &lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;Columns 1 through 16&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0000   -0.0000   -0.0000   -0.0000   -3.0914      -Inf       NaN       NaN       NaN       NaN       NaN       NaN       NaN       NaN       NaN       NaN&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
xd =&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;1.0e+127 *&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Columns 1 through 16&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0.0000   -0.0000   -0.0000   -0.0000   -3.0914      -Inf       NaN       NaN       NaN       NaN       NaN       NaN       NaN       NaN       NaN       NaN</description>
    </item>
    <item>
      <pubDate>Fri, 26 Nov 2010 05:29:26 +0000</pubDate>
      <title>Re: Simple problem</title>
      <link>http://www.mathworks.de/matlabcentral/newsreader/view_thread/297396#799445</link>
      <author>ImageAnalyst</author>
      <description>I don't get anything like that at all.  When I run your code, the only&lt;br&gt;
output is this in the command window:&lt;br&gt;
xd =&lt;br&gt;
&amp;nbsp;&amp;nbsp;859.8028&lt;br&gt;
yd =&lt;br&gt;
&amp;nbsp;&amp;nbsp;265.9682&lt;br&gt;
I'd say what is going wrong is you not using the debugger.  Learning&lt;br&gt;
how to use the debugger is what will allow you to solve problems like&lt;br&gt;
this.&lt;br&gt;
&lt;br&gt;
Your function also looks strange, and not just because there are no&lt;br&gt;
comments in it and you're using i as a loop counter.  You call it and&lt;br&gt;
do a bunch of math but then don't return anything.  Nothing is saved,&lt;br&gt;
plotted, or returned, so what's the point?</description>
    </item>
    <item>
      <pubDate>Fri, 26 Nov 2010 09:39:07 +0000</pubDate>
      <title>Re: Simple problem</title>
      <link>http://www.mathworks.de/matlabcentral/newsreader/view_thread/297396#799480</link>
      <author>Walter Roberson</author>
      <description>On 25/11/10 10:25 PM, Andreas wrote:&lt;br&gt;
&amp;gt; Hello, i have a simple problem. I say that xd(1)=u*cos(theta) but in the&lt;br&gt;
&amp;gt; output it is taken as zero! What i'm doing wrong?&lt;br&gt;
&lt;br&gt;
Are you aware that cos() works on radians? Use cosd() if you want degrees.</description>
    </item>
    <item>
      <pubDate>Sat, 27 Nov 2010 01:07:04 +0000</pubDate>
      <title>Re: Simple problem</title>
      <link>http://www.mathworks.de/matlabcentral/newsreader/view_thread/297396#799682</link>
      <author>Roger Stafford</author>
      <description>"Andreas " &amp;lt;pentaxxx@gmail.com&amp;gt; wrote in message &amp;lt;icncr0$1cq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hello, i have a simple problem. I say  that xd(1)=u*cos(theta) but in the output it is taken as zero! What i'm doing wrong? My code is below and at the end is the output! &lt;br&gt;
&amp;gt; .........&lt;br&gt;
&amp;gt; xd =&lt;br&gt;
&amp;gt;   1.0e+127 *&lt;br&gt;
&amp;gt;   Columns 1 through 16&lt;br&gt;
&amp;gt;     0.0000   -0.0000   -0.0000   -0.0000   -3.0914      -Inf       NaN       NaN ....&lt;br&gt;
- - - - - - - - -&lt;br&gt;
&amp;nbsp;&amp;nbsp;As to your question of why for xd(1) "in the output it is taken as zero!", the answer is that it is NOT zero in the output.  The value of xd(1) has actually not changed at all.  Notice the multiplying factor "1.0e+127 *" above the lines of output.  The closest five decimal place value in x.xxxxe+127 for 859.8028 would have to be 0.0000e+127 !  You should always pay close attention to that multiplicative factor when interpreting your vector or matrix output displays.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Of course the reason that factor is set so high in your display is that later values of xd are enormous and the factor has to be set to handle the largest of these.  By the fifth one it is already up to -3.0914e+127, and at the next step it has exceeded the 'realmax' limit and become -inf.  Whatever you are computing is expanding far faster than you have apparently planned for.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;Out of curiosity just what is it you are attempting to compute?  That "m*g" term suggests the weight of a mass of 600 kg on the earth, but I can't understand why you multiply by yd(i)^2+xd(i)^2 at each step - some kind of force is supposed to increase in direct proportion to the square of the distance rather than inverse proportion?&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
  </channel>
</rss>
