? Input argument y is undefined.

In summary, the conversation discusses an issue with using ode45 in MATLAB and suggests two solutions - defining the function and running ode45 in console, or creating a nested function. It also mentions the possibility of using local and global variables.
  • #1
okkadu
1
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
  • #2
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.
 
  • #3
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:

1. What does it mean when the input argument y is undefined?

When an input argument is undefined, it means that the value for y has not been assigned or is missing. This can occur when the input is not provided or when there is an error in the code that is supposed to assign a value to y.

2. How can I fix the issue of an undefined input argument y?

To fix the issue of an undefined input argument y, you can check your code to make sure that the input is being provided and that there are no errors in the code that assigns a value to y. You can also use conditional statements to handle situations where the input is missing.

3. Can an undefined input argument y cause errors in my code?

Yes, an undefined input argument y can cause errors in your code. This is because the code is expecting a value for y in order to perform certain operations. When y is undefined, the code may not be able to function properly and may produce errors.

4. What types of data can result in an undefined input argument y?

An undefined input argument y can result from a variety of data types. For example, if the input is supposed to be a number but the user enters a string, y may be undefined. Additionally, if the input is an array and the user does not provide any values, y may also be undefined.

5. How can I prevent an undefined input argument y in my code?

To prevent an undefined input argument y, you can perform input validation in your code. This means checking that the input provided is of the correct data type and has a value assigned to it. You can also use default values for input arguments if the user does not provide any input.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
811
Replies
23
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
17K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
0
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
Back
Top