Class blog 2/13 - part 2
ECE 3340 - Han Q. Le (r)
We talked in class about creating a function. We
had a discussion of what can be input of a function? is it number?
string? array? is there any limit to the type of array or array
dimension?
The answer is that
any computable object can be an input. Below is an example.
1. Object input of a function
Recall that we did this in Tutorial 2, and you should have a record of.
Now, we will make a function that uses the object above as input,
2. Making a function using Block or Module
First, let’s review basic steps to make a function. You should follow by typing line by line while trying to learn the structure of a Block function below.
2.1 Basic
You can use Block or Module for the basic structure below:
More specific
2.2 No need for input variables: prompt or does thing automatically
It is OK to have no input variable:
In[1]:=
In[2]:=
Out[2]=
In[1]:=
In[70]:=
2.3 Most useful functions need no input variables: it does thing automatically by looking for things, log-in etc.
3. A Block function that reads your record above
In[4]:=
In[1]:=
Now, go ahead and put in the data record you did for Tutorial 2. Below is an example.
In[3]:=
Out[4]=
Npw, see what the function we design does to the above object.
In[5]:=
Out[5]=
Another example
In[6]:=
Out[6]=
In[7]:=
Out[8]=
End
You are strongly encouraged to go through all the tutorials up to
now. Send in questions if need help.