You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
How to get real and imaginary terms from an expression?
5 views (last 30 days)
Show older comments
I am trying to get real and imaginary terms from the following expression TF. But real(), imag() is not able to give me any solution.
syms s real
ws = 2 * pi * 85000 ;
Lp = 27.13e-6 ;
Cpp = 129.23e-9 ;
Zp = s * Lp + ws * Lp * 1i ;
Zpp = 1 / ( s * Cpp + ws * Cpp * 1i ) ;
TF = Zpp * Zp / ( Zp + Zpp ) ;
These two commands give me following answers.
TFreal = real(TF)
TFreal =
TFimag = imag(TF)
TFimag =
You can observe that the answers have real, imag commands in them instead of answers.
2 Comments
Paul
on 11 Dec 2022
Hi Aditya,
Normally, a transfer function, which I assume is what TF means, is defined as a function of s, which is a complex variable, and all other terms in the tansfer function are all real. But here, we have s defined as real, and other terms in the TF are complex. Can you clarify exactly what this code is intened for?
Accepted Answer
Walter Roberson
on 11 Dec 2022
syms s real
ws = 2 * pi * 85000 ;
Lp = 27.13e-6 ;
Cpp = 129.23e-9 ;
Zp = s * Lp + ws * Lp * 1i ;
Zpp = 1 / ( s * Cpp + ws * Cpp * 1i ) ;
TF = Zpp * Zp / ( Zp + Zpp ) ;
TFreal = real(TF)
TFreal =
TFimag = imag(TF)
TFimag =
simplify(TFreal)
ans =
simplify(TFimag)
ans =
10 Comments
Aditya Zade
on 11 Dec 2022
Edited: Aditya Zade
on 11 Dec 2022
Hi Walter,
Thanks for the comment.
I have more complex expressions where simplify command is not helping me. Can you help me with that?
Id = 2.1467 - 51.0287i ;
Req = 17.5865 ;
Vm = 277 * sqrt(6) ;
ws = 2 * pi * 85000 ;
Lp = 27.13e-6 ;
Cpp = 129.23e-9 ;
Cps = 175.29e-9 ;
Ll = 34.69e-6 ;
Lm = 782.76e-6 ;
syms s real
Zp = s * Lp + ws * Lp * 1i ;
Zpp = 1 / ( s * Cpp + ws * Cpp * 1i ) ;
Zps = 1 / ( s * Cps + ws * Cps * 1i ) ;
Zl = s * Ll + ws * Ll * 1i ;
Zm = s * Lm + ws * Lm * 1i ;
Kp1 = ( Req * ( 1 + ( ( Zps + Zl ) / Zm ) ) ) + Zps + Zl ;
Kp2 = 1 + ( Zp / Zpp ) + ( Zp / ( Zps + Zl ) ) ;
Kp3 = Zp / ( Zps + Zl ) ;
H_mi_idcap = ( 2 * sqrt(3) / pi ) * Vm / ( ( Kp1 * Kp2 ) - ( Req * Kp3 ) ) ;
H_mi_idenvcap = ( simplify( real( H_mi_idcap ) ) * ( real ( Id ) ) + simplify( imag( H_mi_idcap ) ) * ( imag( Id ) ) ) / ( abs( Id ) ) ;
This gives me the following answer where you can see imag and real commands instead of a proper solution. Everything is a function of 's' which I have defined as a real number :
H_mi_idenvcap =
(172683135000208604551535223026586347005871322726587908178108096625276636501114880000000*imag(1/((260655775425866130589094142874939721854279679342140669722801980358790866066735104000000000000*((4003681333757921*s)/147573952589676412928 + (pi*46121i)/10000))/(3199587759584921875*s + pi*543929919129436693725184i + 3484491437270409865864955980101306485309440000/(6622268966257761*s + 3536760160863479398400i)) + (((2441085682324977*s + 1303712463883813781504i)*(2502300833598700625*s + pi*425391141711779115040768i) + (160693804425899027554196209234116260252220299378279283530137600000000*((4003681333757921*s)/147573952589676412928 + (pi*46121i)/10000))/(3199587759584921875*s + pi*543929919129436693725184i + 3484491437270409865864955980101306485309440000/(6622268966257761*s + 3536760160863479398400i)) + 1742245718635204932932477990050653242654720000)*(s*(4619058782255093538217914766794407636638949233813262172160000 - 21168034995631362998836147051869896922367328720757068922880000i) + pi*(78011169021401466968879757554262818755122444066860299426830745600 + 1854409792978907913925284668047915815504542811708541297105253171200i) + pi*s*(6944434942837917949164811082012024629727852242338660690690048 - 146068978425098581708069587328360702057061537084478402330624i) - pi*s^2*6501418518427872464610362653183025793653342863217393664i - s^2*(20247246437114752669473895744275033930756435040419840000 + 40849617310811283933296436264138582256579234682880000000i) - 38243638343693369198375882169918233116530201328125*s^3 + (5388772738081004572469698920051915105680717877468455087175106560000 - 3358895989106063476910444219158740309232214042176845740119162880000i)))/(11952676787541737523111330423471*s^2 + s*12767150139401286081539645192745910272i - 3409280732243783574557653655779097234636800))))/1437601757967713 - (7264420886176792199257085734292880601658091595116561440468289605814950758973440000000*real(1/((260655775425866130589094142874939721854279679342140669722801980358790866066735104000000000000*((4003681333757921*s)/147573952589676412928 + (pi*46121i)/10000))/(3199587759584921875*s + pi*543929919129436693725184i + 3484491437270409865864955980101306485309440000/(6622268966257761*s + 3536760160863479398400i)) + (((2441085682324977*s + 1303712463883813781504i)*(2502300833598700625*s + pi*425391141711779115040768i) + (160693804425899027554196209234116260252220299378279283530137600000000*((4003681333757921*s)/147573952589676412928 + (pi*46121i)/10000))/(3199587759584921875*s + pi*543929919129436693725184i + 3484491437270409865864955980101306485309440000/(6622268966257761*s + 3536760160863479398400i)) + 1742245718635204932932477990050653242654720000)*(s*(4619058782255093538217914766794407636638949233813262172160000 - 21168034995631362998836147051869896922367328720757068922880000i) + pi*(78011169021401466968879757554262818755122444066860299426830745600 + 1854409792978907913925284668047915815504542811708541297105253171200i) + pi*s*(6944434942837917949164811082012024629727852242338660690690048 - 146068978425098581708069587328360702057061537084478402330624i) - pi*s^2*6501418518427872464610362653183025793653342863217393664i - s^2*(20247246437114752669473895744275033930756435040419840000 + 40849617310811283933296436264138582256579234682880000000i) - 38243638343693369198375882169918233116530201328125*s^3 + (5388772738081004572469698920051915105680717877468455087175106560000 - 3358895989106063476910444219158740309232214042176845740119162880000i)))/(11952676787541737523111330423471*s^2 + s*12767150139401286081539645192745910272i - 3409280732243783574557653655779097234636800))))/1437601757967713
Walter Roberson
on 11 Dec 2022
Id = 2.1467 - 51.0287i ;
Req = 17.5865 ;
Vm = 277 * sqrt(6) ;
ws = 2 * pi * 85000 ;
Lp = 27.13e-6 ;
Cpp = 129.23e-9 ;
Cps = 175.29e-9 ;
Ll = 34.69e-6 ;
Lm = 782.76e-6 ;
syms s real
Zp = s * Lp + ws * Lp * 1i ;
Zpp = 1 / ( s * Cpp + ws * Cpp * 1i ) ;
Zps = 1 / ( s * Cps + ws * Cps * 1i ) ;
Zl = s * Ll + ws * Ll * 1i ;
Zm = s * Lm + ws * Lm * 1i ;
Kp1 = ( Req * ( 1 + ( ( Zps + Zl ) / Zm ) ) ) + Zps + Zl ;
Kp2 = 1 + ( Zp / Zpp ) + ( Zp / ( Zps + Zl ) ) ;
Kp3 = Zp / ( Zps + Zl ) ;
H_mi_idcap = ( 2 * sqrt(3) / pi ) * Vm / ( ( Kp1 * Kp2 ) - ( Req * Kp3 ) ) ;
H_mi_idenvcap = ( ( real( H_mi_idcap ) ) * ( real ( Id ) ) + ( imag( H_mi_idcap ) ) * ( imag( Id ) ) ) / ( abs( Id ) )
H_mi_idenvcap =
[N, D] = numden(H_mi_idenvcap);
H_mi_idenvcap = collect(simplify(N), s) / simplify(D)
H_mi_idenvcap =
Aditya Zade
on 11 Dec 2022
Thank you very much. Btw how do you arrange the answer so nicely? Is there any tool for that.
Aditya Zade
on 11 Dec 2022
Edited: Aditya Zade
on 11 Dec 2022
Also, I need to use this 'H_mi_idenvcap' to generate a step response. So, I need it as a transfer function with s = tf('s'). Do you know how can I do that?
TF = tf(N, D) ;
is giving me an error.
Walter Roberson
on 12 Dec 2022
format long g
Id = 2.1467 - 51.0287i ;
Req = 17.5865 ;
Vm = 277 * sqrt(6) ;
ws = 2 * pi * 85000 ;
Lp = 27.13e-6 ;
Cpp = 129.23e-9 ;
Cps = 175.29e-9 ;
Ll = 34.69e-6 ;
Lm = 782.76e-6 ;
syms s real
Zp = s * Lp + ws * Lp * 1i ;
Zpp = 1 / ( s * Cpp + ws * Cpp * 1i ) ;
Zps = 1 / ( s * Cps + ws * Cps * 1i ) ;
Zl = s * Ll + ws * Ll * 1i ;
Zm = s * Lm + ws * Lm * 1i ;
Kp1 = ( Req * ( 1 + ( ( Zps + Zl ) / Zm ) ) ) + Zps + Zl ;
Kp2 = 1 + ( Zp / Zpp ) + ( Zp / ( Zps + Zl ) ) ;
Kp3 = Zp / ( Zps + Zl ) ;
H_mi_idcap = ( 2 * sqrt(3) / pi ) * Vm / ( ( Kp1 * Kp2 ) - ( Req * Kp3 ) ) ;
H_mi_idenvcap = ( ( real( H_mi_idcap ) ) * ( real ( Id ) ) + ( imag( H_mi_idcap ) ) * ( imag( Id ) ) ) / ( abs( Id ) );
[N, D] = numden(H_mi_idenvcap)
N =
D =
19758232616516474986477649920000
N = collect(simplify(N), s);
[N1, D1] = numden(N);
c1 = sym2poly(N1);
c2 = sym2poly(D1);
D = simplify(D);
H_mi_idenvcap = tf(c1./double(D), c2)
H_mi_idenvcap =
2.205e188 s^7 + 8.513e195 s^6 + 3.049e201 s^5 + 5.943e207 s^4 + 1.696e213 s^3 + 1.181e219 s^2 + 2.349e224 s + 5.088e229
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
8.527e170 s^10 + 9.029e176 s^9 + 2.602e183 s^8 + 1.91e189 s^7 + 2.231e195 s^6 + 1.11e201 s^5 + 6.483e206 s^4 + 2.105e212 s^3 + 6.002e217 s^2 + 9.105e222 s + 9.863e227
Continuous-time transfer function.
Aditya Zade
on 12 Dec 2022
One of my transfer function is mentioned below. The problem is matlab is considering it as inf/inf which is giving me NaN in TF. How can I reduce the accuracy of each cofficients such that matlab doesn't consider numerator and denominator as inf.
In other words, how can I make this expression into a TF to generate bode plots.
H_mi_idenvecap = (3198609293274692543065653067624214930931010880602439324145398125122373719207088478979647504147912365379393279754941675512836511355487782993690473574523041631084160518721751172162257705176739868804951103644988270056301183639951764002961292649184871320805158132898539453590562021769463423670681600*s^10 + 528394964584010682783572570459412119664515594164049190345558269437867459470515176667326104615180103456012477355413596835172119921200079260151617877500088502992749340415451742149406277381474643891231659256544455164436234396533126019809440535921033867151082644616021673572586341975274322902549476147200*s^9 + 3364815264139209882761251038034730020362043044801573317888318745671317862412400497423209337541418420521260443952869134388981445799336993041335421299405549089717062472469931053659028441787475552139751801731258711488308627072509140489498330224609031510667147325022465839409185515146370263699813850219632656384*s^8 + 563685908110931596054975975789145169901513780980290358304128472564818439113945323667367115971977027594918152558869188644661828289297726904892093313231476094308350368709481298326017516778957422345680859263591644269304648598798995637702553858174358334141567592255906469564947805207135557231654360809390637347504128*s^7 + 1490257685171315468981773939159767624935105379546903549767553901546757666260988184536138242660525137524427599600907269172197568037353264870592893757184448550843993106896014192025989160859007053395078824566748256700430184559758347451096212214570755769067612673807213370221663874574993990956271545381513459363454956601344*s^6 + 224411121359031406238956529185520395250362431900419601379549724354175300141779807782002787175390937335420258029478904711464033857382032746518758309250170139544602989872581677894407504342046674752426946975585667274279454218538522463096065609371083080593692625877514805336214723108899068335933784036977289350835195383669325824*s^5 + 313435614540771365005472378788015656763925845027971206036651498864090340592352682307018010940557769472344445076584267523825439903337732769841322691195467198038852610063857978387582140881350878878314891681041745284058278276910429225911095101311401498430011153223268796705288141506966312381716632816295470628030364360123375283077120*s^4 + 33052372310506629010656599121147115620859961521559341305146351113127420214834631202990344435993579760702170846892190791973857746526095679537107762472443219962883772363971249591309331211286424393764376285694816602968673940014673553192267278248106274456921340775937053409889209132481984880619358508372583085903071902984276537872895442944*s^3 + 10554849876610050019218981278396688996628674897403163356241700611846899932472970866934831849299194775963827696479104585836123032305509546783003015154442878237125239205963612543055962962608195786274300100491480333594963695160464423230708118733213297370805489181822237410178521006221240286568706063689875376392244199192804233754948767114592256*s^2 + 753392467992893717086282360117150962316839153406675455633706582201238077981189206904259370759701924447550938546700321591834810653022526799241547416036382680758251634390626464710218582595943371303498239715517551074690452253677797215333441705005554261781839683641360100743141925156332627926700008050827621415436588867603559400388725106077190848512*s + 40393566359665865213299995369702801378786875218724874851168023401021269156066673958605743192955287230615526894469312967897474790091218367504457257709499999902912836650529949891815535967261169141147611466577851052777443496008708518428106932969186262475588373778567341855852815573620320080624013993765045842114972784171785710233396747569200139998330880)/(8796093022208*(1736567701589301145136648268745070267169586006463452702588095291310545287345936191207231693796554822487658048259058768341620886269302733511008839672446368759925297181964446329483562182298316297460367920025475136735375318177318220152446938927265225*s^16 + 717181706990849576639378846143604344747449411096706760755432781269930354932423747033964722181786892343713490722151365999943109079738204766382874076277599763531511760836188464560773573023546208271499106196789947712108879925411040105198246484299810406400*s^15 + 8474902337396137452537172814758191980658242868146989657851391747578894251875032832065877742822364594666025855664179609126663161480336968740345550831115764290784755921679756769231426450016836146980279285273763923555792818972379443730261637462558119995610497024*s^14 + 3060326629338539947795355844711670424230830104533914727180539407962588796854615013646350523884347125794176122078030819700072795725888050006338552712785006937280184063404052729170190527501487957786817505885405810768143497607256181752489430834429438245071731940130816*s^13 + 15335444336168058219053185629448334708949063277544031136997077132483020621337637079802757161722640630404872281753614633056555568331414532672223094357966529046772826765042453467781257350997846896530993396891805695459960227266764332535793736164051751621607630139917288341504*s^12 + 4711858733362574057644866067860734266890167073692817480732992906997138035715344442510025574475777812882693974120674123611995382178060815482516053616266140291523815161417712375969402534241363378219168042007415040048566795665071810311976396545823703304132119454866433941966946304*s^11 + 12461014205963250065638676548329519983986852678656821442028223071451986862953854290657145129348903622243955644402794979315564378889686689969794544728780606414037860400637500820387005456202310836355975107206149920656892865375979089113148380105538910212977991189672316595043017557016576*s^10 + 3153610764893990481124174423558310705947546643632994209428020901123162737494351255973870435414198228754915355165434369521635012685859083006757509655278714956660143488334593307926704075313537591188840386118802653628117669854992826061562111167065459384377864567395435560227329653331202146304*s^9 + 4196412284794922572702360089303675577340283804488759850189612200368294017368398595914096366806020918778693395129234114128153062192604212478313975760328409295684988085937308175782203157955672589220365686768906199996621051328446913656225084261462685321058494326091046314623083166983844470867361792*s^8 + 839696424033259323305277259210900820320478003816838709480281015945809199296634999150590387829225143482425327884290937963213529918958215499963010050257883261661116698672089983062272555691561771948624741135615136402177972155830430074599923524875698012649853320313826785826359259368579738843006040539136*s^7 + 341072015811716244581240425181942419448756068895024422843527961260011128604733215760197603405155010453702864279995268573154131226786824324708691134950163294295325223338672708909939254713696078247686589394867848835471068071716381633979836751951857567203826189555176612717339907046903740670679827717512232960*s^6 + 51476173533824520781908853124919012872558430328391461780218775183986801463554817939279579606358525500680300575053075911956606069305313326101015765941389705874779285216218534083105540702681692717458081833490789076288368074605827448462551175726017448688748586848426830311404300308080734687142200861235996885254144*s^5 + 9228963476387818526423807612115148970316248169275808385076365503267308598269819401998734036439982463217524876484624976388723299159343094174914050928582387570266303834881596621229787172099209884856109159135095077583516660315341853942084463079767357281710097403352648761070698296853785890788932711840594861082305101824*s^4 + 911043127300211915454447709952136661126629354017481583423569852460766841727455715209418097330189535279221498687673228467765980464696556517614401815146230080830691482821416104568196921957378920491489758562441974400120279545914620076777651283757517630045507906342397020857506949542233013765663031850658377453871364193648640*s^3 + 75868678050389397096199117807278223110751098365028855498075829798267143867014386665936900343279698677835660735344427396694303631098532043960596038629673009001621357014913910492452492780815641595686087435829590661675243076354379570729851910901126879665446131462508434640539917488307446180193941439583412905434367223985904549888*s^2 + 3174513831849780742601338555460290943793994469034596358746253922613510616605561379821305476696010693727089813475729119325248586731428000109372903713452154026995530738937814787974412887244775242394586804120936971001141865477711946150235680311292016446655479884972049090441497967508802274262026411582423828562014806418492161112670208*s + 85101763546936457815360949157574484179847571907787276421705398659175650996907399114220574701462894693638387449557772198429740759814194738572525547329802602231403046298633131911713278866661938182354784531853129097941253657184023638815783627856915654844607628228041193047656641242417683444772761706726371526915906514106247461005512671232))
More Answers (0)
See Also
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)