Solved. Thanks artikk!

tboo

Diamond Member
Jun 25, 2000
7,626
1
81
Im trying to create a function that will return a transfer function by inputting a pole &/or its complex conjugate. This would be for poles only-no zeros.

so if I enter func(-1) it will return : transfer function: 1/s^2+2s+1

Any help is appreciated. I suck at Matlab.
 
Last edited:

Saint Nick

Lifer
Jan 21, 2005
17,722
6
81
It was a joke buddy :p It's Friday...lighten up :p

Edit: Sorry if it came off as douchey :( Just making a joke!
 
Last edited:

busydude

Diamond Member
Feb 5, 2010
8,793
5
76
You are going to have infinite different answers for your problem. You need to be more specific.
 

tboo

Diamond Member
Jun 25, 2000
7,626
1
81
Ive tried several iterations. None have worked. Here is the latest:


function [num den p h] = rsys(x,y,z)
num =[0 0 1];
p=poly([x y z]);
den=p;
h=tf(num,den);
 
Last edited:

randomrogue

Diamond Member
Jan 15, 2011
5,449
0
0
Pro tip: Buy the book that has like every function and an explanation and example of it.

I made a really big mistake for a huge project where I wrote up a modeling program with multiple nested loops and checks only to find out that there was one line of code that I could have used. The only good news is that there were people dumber than me who used excel to do it and it took them 2 days to get an answer each time they tested it. That spreadsheet was the most ridiculous thing I think I ever saw in college and brought computers to their knees.
 

artikk

Diamond Member
Dec 24, 2004
4,172
1
71
You should have googled more. Anyway, here's my final response.
z = vector of zeros, form: z=[x y z]; In your case make it empty, e.g. z=[];
p=vector of poles, form: p=[x y z];
k=overall system gain, make it=1;
[num,den] = zp2tf(z,p,k)
then transform into transfer function
sys=tf(num, den);
 

tboo

Diamond Member
Jun 25, 2000
7,626
1
81
You should have googled more. Anyway, here's my final response.
z = vector of zeros, form: z=[x y z]; In your case make it empty, e.g. z=[];
p=vector of poles, form: p=[x y z];
k=overall system gain, make it=1;
[num,den] = zp2tf(z,p,k)
then transform into transfer function
sys=tf(num, den);

Will that work with complex numbers? For example, I need to be able to enter function(-8 -.5+.7071i -.5-.7071i) & get back transfer function: 1/s^3 +9s^2 +35/4s +6

I can do it in the command window using this:

num=[0 0 1];
>> p=poly([-8 -.5+.7071i -.5-.7071i]);
>> den=p;
>> tf(num,den)

Transfer function:
1
------------------------
s^3 + 9 s^2 + 8.75 s + 6


I just need to figure out how to turn it into a function where I enter the poles & get a transfer function back
 
Last edited:

artikk

Diamond Member
Dec 24, 2004
4,172
1
71
Will that work with complex numbers? For example, I need to be able to enter function(-8 -.5+.7071i -.5-.7071i) & get back transfer function: 1/s^3 +9s^2 +35/4s +6

I can do it in the command window using this:

num=[0 0 1];
>> p=poly([-8 -.5+.7071i -.5-.7071i]);
>> den=p;
>> tf(num,den);
>> tf(num,den)

Transfer function:
1
------------------------
s^3 + 9 s^2 + 8.75 s + 6


I just need to figure out how to turn it into a function where I enter the poles & get a transfer function back

The code that you showed does this already as a final step. Are you talking about making a custom function that uses the code above to output what you want? Because that would be really pointless just to save a couple of lines of code.
 
Last edited:

tboo

Diamond Member
Jun 25, 2000
7,626
1
81
The code that you showed does this already as a final step. Are you talking about making a custom function that uses the code above to output what you want? Because that would be really pointless just to save a couple of lines of code.

Yes, I need to make a custom function to give me a transfer function with whatever poles I enter(no zeros).
 

artikk

Diamond Member
Dec 24, 2004
4,172
1
71
Yes, I need to make a custom function to give me a transfer function with whatever poles I enter(no zeros).

DON'T FORGET TO DO THIS FIRST.
Save the code as .m file with filename given by the function name("pole_to_tf.m" in this case) and set path to it by going to File>Set Path...

Now here's the function's code:

function [tf_out] = pole_to_tf(poles)
%Calculates transfer function given
%inputs: poles
num=[0 0 1];
p=poly([poles]);
den=p;
tf_out=tf(num,den);

end

To see output just type(without semicolon):
tf_out=pole_to_tf([-8 -.5+.7071i -.5-.7071i])

Transfer function:
1
------------------------
s^3 + 9 s^2 + 8.75 s + 6

Phew, that was just tedious.
 

tboo

Diamond Member
Jun 25, 2000
7,626
1
81
DON'T FORGET TO DO THIS FIRST.
Save the code as .m file with filename given by the function name("pole_to_tf.m" in this case) and set path to it by going to File>Set Path...

Now here's the function's code:

function [tf_out] = pole_to_tf(poles)
%Calculates transfer function given
%inputs: poles
num=[0 0 1];
p=poly([poles]);
den=p;
tf_out=tf(num,den);

end

To see output just type(without semicolon):
tf_out=pole_to_tf([-8 -.5+.7071i -.5-.7071i])

Transfer function:
1
------------------------
s^3 + 9 s^2 + 8.75 s + 6

Phew, that was just tedious.

Thanks for your help artikk. Ill give it a try.
 

artikk

Diamond Member
Dec 24, 2004
4,172
1
71
Thanks for your help artikk. Ill give it a try.

After plugging in different poles and higher order poles, the function works for all iterations of poles given there are no zeros
 
Last edited: