On May 12, 2010, at 7:55 AM, Shravan S wrote:
Dear MEEP users,
I have been trying to transmit a chirp signal in meep using the custom-src option. My custom function takes an argument as time (in meep units; I am using meep-time function for that) and returns a complex number. The function by itself works properly. But when I use it in custom-src i get an error saying: wrong type to apply 'x', x is some value generated by the function.
 e.g. wrong type to apply 1.4462414 + .59983638i.
I think it has something to do with how the function output is passed to src-func( ) (under custom-src), but I am not able to figure it out. Please suggest as to what can be done. I have attached the .ctl file for your reference. It can be opened in wordpad.

This is a common confusion. You are passing not the function, but rather the result of evaluating the function, as the src-func argument. You wrote:

                                (src-func
                                        ( (chirp ( (meep-time)) ))

In fact, this has multiple problems. What you have to realize first is that parentheses are important in Scheme --- arguably, they are the single most important syntactical element in the language. You can't just add parentheses arbitrarily, like you can in C, without dramatically changing the meaning of what you are doing.

For example, meep-time is a *function* that returns the time (in the simulation). (meep-time) is the *result* of evaluating that function, i.e. a number. ( (meep-time)) is telling Scheme to first evaluate meep-time (first parens) and then evaluate the *result* of calling meep-time as if it were a function (second parens). Since the result of (meep-time) is a number, not a function, doing ((meep-time)) will give an error. Your code above repeats this error several times.

You didn't attach the code for your chirp function, but I'm assuming that it is a function of one argument that gives the current you want, i.e. it is called like (chirp t). In this case, you should use:

        (src-func chirp)

That is, the argument of src-func is the *function* that you want, *not the result* of calling the function.

Steven

_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

Reply via email to