for loop in matlab

1 次查看(过去 30 天)
grace lim
grace lim 2022-3-31
syms Av Riopamp Riminus Rf Ro omega Ciminus
h11=Riopamp+((Riminus*Rf)/(Riminus+Rf))
h12=Riminus/((Riminus+Rf))
h21=-(((Av*Riopamp)/Ro)+(Riminus/Rf))
h22=(Ro+Riminus+Rf)/((Ro*(Riminus+Rf)))
h11new=subs(h11,Riminus,Riminus-(1/(1i*omega*Ciminus)))
simplify(h11new)
how to repeat this code(bottom) for all h12 h21 h22?
h11new=subs(h11,Riminus,Riminus-(1/(1i*omega*Ciminus)))

回答(1 个)

Santosh Fatale
Santosh Fatale 2022-4-7
Hi Grace,
I understand that you have four symbolic variables h11, h12, h21, h22. You expressed the respective expression for each of these variables using other symbolic variables. You want to substitute new value for one of the symbolic variable which is a part of the expression and evaluate expression of variables h11, h12, h21, and h22 for this new value. I would like to suggest you to use struct datatype as follows to ease tasks which you want to achieve.
syms Av Riopamp Riminus Rf Ro omega Ciminus
T = struct;
T.h11=Riopamp+((Riminus*Rf)/(Riminus+Rf))
T.h12=Riminus/((Riminus+Rf))
T.h21=-(((Av*Riopamp)/Ro)+(Riminus/Rf))
T.h22=(Ro+Riminus+Rf)/((Ro*(Riminus+Rf)))
h11new=subs(T,Riminus,Riminus-(1/(1i*omega*Ciminus)))
for iterVar1 = 1 :2
for iterVar2 = 1: 2
simplify(h11new.("h"+iterVar1+iterVar2))
end
end
The individual fields of the structure, which are variables in your case, can be accessed by dot notation as follows:
>> T.h11
For more info on struct datatype, please check out the documentation link.

类别

Help CenterFile Exchange 中查找有关 Numbers and Precision 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by