• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Solved. Thanks artikk!

tboo

Diamond Member
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:
It was a joke buddy 😛 It's Friday...lighten up 😛

Edit: Sorry if it came off as douchey 🙁 Just making a joke!
 
Last edited:
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:
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.
 
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);
 
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:
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:
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).
 
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.
 
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.
 
Back
Top