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
Click For Summary

Discussion Overview

The discussion revolves around the use of basic MATLAB functions, specifically how to define and utilize them in the context of solving differential equations using ODE45. Participants share experiences and seek clarification on function definitions and their applications.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant describes an issue with defining a function in MATLAB and receiving an error regarding an undefined input argument.
  • The same participant later realizes that they need to call the function with an argument (e.g., u(2)) to obtain a value.
  • Another participant suggests consulting the online documentation for structuring arguments in MATLAB's ODE solvers and provides links to relevant resources.
  • There is a mention of the importance of bookmarking the MATLAB documentation for comprehensive guidance.

Areas of Agreement / Disagreement

Participants generally agree on the usefulness of the documentation and the need to correctly structure function calls, but the discussion does not resolve any broader questions about using ODE45 or the specific differential equation mentioned.

Contextual Notes

Limitations include the initial misunderstanding of function calls in MATLAB and the lack of detailed discussion on how to implement the differential equation with ODE45.

Who May Find This Useful

Individuals new to MATLAB, particularly those looking to understand function definitions and their application in solving differential equations.

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:
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K