? Input argument y is undefined.

  • Thread starter Thread starter okkadu
  • Start date Start date
  • Tags Tags
    Argument Input
okkadu
Messages
1
Reaction score
0
? Input argument "y" is undefined.

HII Friends
Iam little bit new to MATLAB and iam trying to use ode45 and wrote code as

function dy = sampleode(t,y)

dy=zeros(2,1);

dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);

dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));

[t,y]=ode45('sampleode', [0:5:40],[1;1]);


BUt iam getting the below error:

? Input argument "y" is undefined.

Error in ==> sampleode at 3
dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);
I saved my mfile as sampleode.m .please suggest me any suggestions. Thanks in advance
 
Mathematics news on Phys.org
Hi,

I'm also a newbie in MATLAB, but two things strike me as odd here
1) In the following line you multiply by 0. Did you really mean to do that?
dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));
2) I was under the impression ode45 required a function handle not a string containing the name of the function (though I may be wrong there)
Moreover, what are you inputing as your y as you didn't give the command you use to run the function.
Regardless, sorry I can't be much help.
 
Matlab is strange when working with functions.

One solution is to define the function (and save it in an .m file) and then running ode45 in console. The other (wich i prefer) is to work with nested functions.

In the first one, you should do a sampleode.m file with the following code

Code:
function dy = sampleode(t,y)
  dy=zeros(2,1);
  dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);
  dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));
end

and then in console type

Code:
[t,y]=ode45(@sampleode, [0:5:40],[1;1]);

(nothe the @).

The second solution works better when you are using a more sophisticated code and would be using nested functions. Create a file named ord.m with the following code:

Code:
function ord

[t,y]=ode45(@sampleode, [0:5:40],[1;1]);

  function dy = sampleode(t,y)
    dy=zeros(2,1);
    dy(1)=-0.192*y(1)*log(y(1)/y(2).^3);
    dy(2)=(1/3)*(5.85-0.00873*y(2).^2-0.15*0*y(2)-0.02*y(2));
  end

end

That way, when you type
Code:
ord
in console, Matlab will perform ode45 on the function sampleode. If you add the line
Code:
plot(y,U);
after ode45 but before defining sampleode, then Matlab will perform ode45 and plot the solution every time you type
Code:
ord
in console.

You should check the diference between local and global variables, it could provide another way of solving your problem.
 
Last edited:
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
Thread 'Imaginary Pythagorus'
I posted this in the Lame Math thread, but it's got me thinking. Is there any validity to this? Or is it really just a mathematical trick? Naively, I see that i2 + plus 12 does equal zero2. But does this have a meaning? I know one can treat the imaginary number line as just another axis like the reals, but does that mean this does represent a triangle in the complex plane with a hypotenuse of length zero? Ibix offered a rendering of the diagram using what I assume is matrix* notation...

Similar threads

Back
Top