-1

I need to substitute a value for s in a transfer function. For example:

G(s)= 1/ (s+3)

I need to substitute

s = -2.118 +2.221j

What code should I use for this?

PS: Unfortunately, I only have control system toolbox in MATLAB.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Anu
  • 3
  • 4

2 Answers2

2

What's wrong with saving m-file with

 function g = transferFun( s )
 g = 1 ./ ( s + 3 )

And then calling the function

 >> transferFun( -2.118 + 2.221*j )
Shai
  • 111,146
  • 38
  • 238
  • 371
  • Thankyou Shai..but it doesnt seem to work. Is there any other option – Anu Aug 29 '13 at 10:21
  • @Anu - what do you mean by "doesn't seem to work"? do you get an error? not the expected results? you'll have to provide more details and information in order to get reasonable answers here... – Shai Aug 29 '13 at 11:19
  • 1
    @Anu Make sure your m file is called `transferFun.m` – Dennis Jaheruddin Aug 29 '13 at 11:37
  • @Shai.. Thankyou. I renamed the m file to transferFun.m Its perfectly working. – Anu Aug 30 '13 at 11:42
  • @Anu I'm glad this works for you. Feel free to "accept" this answer by clicking the "V" icon beside it. – Shai Aug 30 '13 at 12:08
1

As shai mentioned you can simply create an m file with the function.

However, if you are just doing some quick calculations here is a way to just do it on the command line. You can define an anonymous function like this:

 G = @(s) 1/(s+3)

Now you can simply call it like this:

G(-2.118 +2.221j)

Note that Matlab is case sensitive.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • I would use './' in `G` in case @Anu decides he wants `s` to be a vector... Wouldn't you agree? – Shai Aug 29 '13 at 11:47
  • @Shai I agree that using `./` would be more robust, but that is more a comment to the question. This is the most straightforward implementation of the given function. – Dennis Jaheruddin Aug 29 '13 at 11:53