MATLAB Understanding Basic MATLAB Functions: How to Use and Define Them

  • Thread starter Thread starter rem88
  • Start date Start date
  • Tags Tags
    Function Matlab
AI Thread Summary
The discussion revolves around a user seeking help with a MATLAB function designed to compute a value based on an input variable, s. The user initially encounters an error stating that the input argument "s" is undefined when trying to evaluate the function. The issue is resolved when the user realizes they need to call the function with an argument, specifically using u(2) instead of just u. Following this, the user seeks guidance on how to integrate this function into a differential equation using MATLAB's ODE45 solver. Suggestions include consulting MATLAB's online documentation for proper structuring of arguments in ODE solvers and bookmarking the documentation for comprehensive guidance. The importance of utilizing MATLAB's help features for better understanding and troubleshooting is also emphasized.
rem88
Messages
4
Reaction score
0
Hi, sorry to ask this, i know its really simple. I tried to look online for help but i couldn't understand why i was going wrong.

I have a function u = [0.25*s]/[0.005 + s]

I put this in a .m file.

I am going to use this by puting an initial value (so) into find u. Then u is used in a differential equation to find a new s.

but when i for example write, s=2 iget this message


>> s=2

s =

2

>> u
? Input argument "s" is undefined.

Error in ==> u at 2
u = [0.25*s]/[0.005 + s]
>>



this is my m file

function u = f(s)
u = [0.25*s]/[0.005 + s]

i haven't really used mat lab before so any help would be great.

Thanks, rem
 
Physics news on Phys.org
Sorry, just figrued it out, i have to put in u(2)

But does anyone know how i know use this to put into a differentail equation (useing ODE45) to generate a new value for s. (which will b e used again in the differential)
 
You may want to take a look at the online documentation for how to structure arguments going into one of MATLAB's ODE solvers:
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/ode23.html

Additionally, I've posted this before in this forum, but MATLAB scripts and functions (those are the m-files you posted previously):
http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f4-2525.html

If you're just starting out with MATLAB, I highly recommend book marking the MATLAB documentation webpage... It's more comprehensive and detailed than the built-in MATLAB documentation (which is decent for on-the-fly reference). If you wanted details about, say, the 'eye' function (identity matrix generator) you would just type in

>> help eye
 
Last edited by a moderator:
Thanks, the links you hav posted look very helpul.

Than you :smile:
 

Similar threads

Back
Top