Understanding Basic MATLAB Functions: How to Use and Define Them

  • Context: MATLAB 
  • Thread starter Thread starter rem88
  • Start date Start date
  • Tags Tags
    Function Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
3 replies · 5K views
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 have posted look very helpul.

Than you :smile: