<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264863</link>
    <title>MATLAB Central Newsreader - using global variable in equation used by ODE solver</title>
    <description>Feed for thread: using global variable in equation used by ODE solver</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 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.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 03 Nov 2009 18:35:04 -0500</pubDate>
      <title>using global variable in equation used by ODE solver</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264863#691795</link>
      <author>Tariq </author>
      <description>i have problem in my program&lt;br&gt;
i created one variable 'v' in main file , the value of that variable is used in the equation in other program as global variable.&lt;br&gt;
&lt;br&gt;
when i run main program having ode45 solver for that equation having variable 'v' it gives error &lt;br&gt;
??? Error using ==&amp;gt; odearguments at 117&lt;br&gt;
Solving EGG2 requires an initial condition vector of length 1.&lt;br&gt;
can any body guide me about this.&lt;br&gt;
&lt;br&gt;
is there is way to use value of one variable in other function (equation) which will be solved through ODE solver.&lt;br&gt;
my code is &lt;br&gt;
&lt;br&gt;
main program&lt;br&gt;
--------------------&lt;br&gt;
clc;&lt;br&gt;
clear all;&lt;br&gt;
global v;&lt;br&gt;
x=[-1;1];  &lt;br&gt;
v= 2*x;&lt;br&gt;
[x,y]= ode45(@eg,[-1 1],[0.1],v);&lt;br&gt;
plot (x,y);&lt;br&gt;
--------------&lt;br&gt;
function  dy =eg(x,y)&lt;br&gt;
global v; &lt;br&gt;
dy= -v*y + x;&lt;br&gt;
end</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 23:04:54 -0500</pubDate>
      <title>Re: using global variable in equation used by ODE solver</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264863#691874</link>
      <author>Nasser M. Abbasi</author>
      <description>&lt;br&gt;
&quot;Tariq &quot; &amp;lt;t.umer@lancaster.ac.uk&amp;gt; wrote in message &lt;br&gt;
news:hcpt4o$n8b$1@fred.mathworks.com...&lt;br&gt;
&amp;gt;i have problem in my program&lt;br&gt;
&amp;gt; i created one variable 'v' in main file , the value of that variable is &lt;br&gt;
&amp;gt; used in the equation in other program as global variable.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; when i run main program having ode45 solver for that equation having &lt;br&gt;
&amp;gt; variable 'v' it gives error&lt;br&gt;
&amp;gt; ??? Error using ==&amp;gt; odearguments at 117&lt;br&gt;
&amp;gt; Solving EGG2 requires an initial condition vector of length 1.&lt;br&gt;
&amp;gt; can any body guide me about this.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; is there is way to use value of one variable in other function (equation) &lt;br&gt;
&amp;gt; which will be solved through ODE solver.&lt;br&gt;
&amp;gt; my code is&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; main program&lt;br&gt;
&amp;gt; --------------------&lt;br&gt;
&amp;gt; clc;&lt;br&gt;
&amp;gt; clear all;&lt;br&gt;
&amp;gt; global v;&lt;br&gt;
&amp;gt; x=[-1;1];&lt;br&gt;
&amp;gt; v= 2*x;&lt;br&gt;
&amp;gt; [x,y]= ode45(@eg,[-1 1],[0.1],v);&lt;br&gt;
&amp;gt; plot (x,y);&lt;br&gt;
&amp;gt; --------------&lt;br&gt;
&amp;gt; function  dy =eg(x,y)&lt;br&gt;
&amp;gt; global v;&lt;br&gt;
&amp;gt; dy= -v*y + x;&lt;br&gt;
&amp;gt; end&lt;br&gt;
&lt;br&gt;
The problem is in your eg function.&lt;br&gt;
When you type   &quot;v*y&quot;, notice that v is a vector of length 2, so this causes &lt;br&gt;
dy to become a vector of length 2, hence the problem.&lt;br&gt;
&lt;br&gt;
I do not know what you are doing here. And why you are passing 'v' to ode45 &lt;br&gt;
since it is allready global. try v scalar, and try this&lt;br&gt;
&lt;br&gt;
v= 99;&lt;br&gt;
[x,y]= ode45(@eg,[-1 1],[0.1]);&lt;br&gt;
&lt;br&gt;
--Nasser</description>
    </item>
    <item>
      <pubDate>Fri, 06 Nov 2009 14:06:03 -0500</pubDate>
      <title>Re: using global variable in equation used by ODE solver</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264863#692677</link>
      <author>Tariq </author>
      <description>hello dear,&lt;br&gt;
thanks for you response , i have checked the error ,&lt;br&gt;
it is ok, how i can get specific value of v from the vector having different values of v to be used in the equation in eg (eq for ode solver). &lt;br&gt;
&lt;br&gt;
&quot;Nasser M. Abbasi&quot; &amp;lt;nma@12000.org&amp;gt; wrote in message &amp;lt;qG2Im.43$gg6.15@newsfe25.iad&amp;gt;...&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &quot;Tariq &quot; &amp;lt;t.umer@lancaster.ac.uk&amp;gt; wrote in message &lt;br&gt;
&amp;gt; news:hcpt4o$n8b$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; &amp;gt;i have problem in my program&lt;br&gt;
&amp;gt; &amp;gt; i created one variable 'v' in main file , the value of that variable is &lt;br&gt;
&amp;gt; &amp;gt; used in the equation in other program as global variable.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; when i run main program having ode45 solver for that equation having &lt;br&gt;
&amp;gt; &amp;gt; variable 'v' it gives error&lt;br&gt;
&amp;gt; &amp;gt; ??? Error using ==&amp;gt; odearguments at 117&lt;br&gt;
&amp;gt; &amp;gt; Solving EGG2 requires an initial condition vector of length 1.&lt;br&gt;
&amp;gt; &amp;gt; can any body guide me about this.&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; is there is way to use value of one variable in other function (equation) &lt;br&gt;
&amp;gt; &amp;gt; which will be solved through ODE solver.&lt;br&gt;
&amp;gt; &amp;gt; my code is&lt;br&gt;
&amp;gt; &amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; main program&lt;br&gt;
&amp;gt; &amp;gt; --------------------&lt;br&gt;
&amp;gt; &amp;gt; clc;&lt;br&gt;
&amp;gt; &amp;gt; clear all;&lt;br&gt;
&amp;gt; &amp;gt; global v;&lt;br&gt;
&amp;gt; &amp;gt; x=[-1;1];&lt;br&gt;
&amp;gt; &amp;gt; v= 2*x;&lt;br&gt;
&amp;gt; &amp;gt; [x,y]= ode45(@eg,[-1 1],[0.1],v);&lt;br&gt;
&amp;gt; &amp;gt; plot (x,y);&lt;br&gt;
&amp;gt; &amp;gt; --------------&lt;br&gt;
&amp;gt; &amp;gt; function  dy =eg(x,y)&lt;br&gt;
&amp;gt; &amp;gt; global v;&lt;br&gt;
&amp;gt; &amp;gt; dy= -v*y + x;&lt;br&gt;
&amp;gt; &amp;gt; end&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The problem is in your eg function.&lt;br&gt;
&amp;gt; When you type   &quot;v*y&quot;, notice that v is a vector of length 2, so this causes &lt;br&gt;
&amp;gt; dy to become a vector of length 2, hence the problem.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I do not know what you are doing here. And why you are passing 'v' to ode45 &lt;br&gt;
&amp;gt; since it is allready global. try v scalar, and try this&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; v= 99;&lt;br&gt;
&amp;gt; [x,y]= ode45(@eg,[-1 1],[0.1]);&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; --Nasser&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; </description>
    </item>
  </channel>
</rss>

