Borrar filtros
Borrar filtros

我使用循环得到m{1​49}和PP{150​,149}关于a的函​数表达式,然后在它们​等于30时侯的根,但​运行太慢,有没有什么​好的解决办法

2 visualizaciones (últimos 30 días)
玉成
玉成 el 28 de Jun. de 2022
Editada: Jeffrey Clark el 29 de Jun. de 2022
clear
clc
x=[0,0.0810795702470861,0.338893857750972,0.289608984180225,0.373884785059033,0.419305386647289,0.381255405793147,0.387805825669320,0.473950108456370,0.777482062955663,0.899607314986380,0.879732671835855,0.642150284769991,0.686654174145980,0.733665507297614,0.648550239659963,0.792221920178573,0.858663843400142,0.950901518893565,0.908403222771981,0.841901725388123,0.803776648251092,0.685298083103286,0.642201303788118,0.758140400904556,0.497859095240467,0.299720346945175,0.330083731903406,0.399635177673192,0.308616636693337,0.406471800425586,0.596726876476001,0.715214262626168,0.550458743758525,0.492048935650519,0.419049480913983,0.412200268366443,0.364288733652186,0.295831971015213,0.576419028947360,0.574301385466896,0.596020783630510,0.674243062495796,0.498132386268964,0.397725957361996,0.502159675610620,0.592607341674827,0.492748845200838,0.683134575176520,0.723692678801045,0.791615285736084,0.856438696079586,0.838872071129628,0.660231299794271,0.697676532404639,0.554721614799348,0.589892742846681,0.673120226900998,0.756160690500417,0.639809622049692,0.746181259265069,0.654068062590623,0.747902390546003,0.887201993210606,1.15338612214489,0.958977631327466,1.12987192182697,1.17636074235029,1.23483468030576,1.23269555488261,1.33231404505112,1.37060109996512,1.36433302688288,1.36920419311632,1.52115837829399,1.65834482953446,1.87356345706959,1.99647272427397,2.05601842308497,1.99102453480784,2.11084190188162,2.15306161675519,2.26308133401253,2.45670787883561,2.47836705949687,2.50236540231708,2.55557973733006,2.66947127745567,3.01512570503452,2.99371227198361,3.25320110604215,3.31695082167831,3.52252671263044,3.62307908694682,3.64950604277507,3.71171958790155,3.92900862767658,4.18624573833328,4.40580642424208,4.43349562449954,4.37047086316136,4.52217706074632,4.69096186724754,4.47614654427472,4.58321154245995,4.95328125690921,5.03544570887013,5.06096113419815,5.04148762518430,4.92141732190889,4.96950751489138,5.11863558218135,5.10618007179529,5.25124128844036,5.46491228721431,5.50486562885070,5.68312502453605,5.87165380633716,5.98423928608256,6.35071262361604,6.30979036073293,6.46558377293770,6.47035888195859,6.50206243202057,6.68184170578453,6.94508314353340,7.09259966782103,7.38465156007102,7.39499822256765,7.56677221290127,7.62961885234629,7.66481995486628,7.46395102011682,7.69310729809314,8.06425918178358,8.26245926894464,8.57255189453345,8.71701239391423,8.69937525807431,8.72801534449858,8.76648524557879,9.04692602569443,9.12816457617079,9.28273121221453,9.25809977088039,9.37994368599395,9.32028599442426,9.37843566395927,9.62250467915979];
t=[0:0.1:14.8];
r=148
u(1)=0.0001;%初始化量
p(1)=0.0001;
s(1)=0.0001;
Q(1)=0.25;
k=1
for i=2:r
O{i+1}=@(a)(t(i+1)).^a-(t(i)).^a;
O{2}=@(a)t(2).^a-t(1).^a;
m{1}=u(k);
m1{2,1}=m{1}
PP{1,1}=p(k);
PP{2,1}=PP{1,1}+Q(k)
K{2}=@(a)PP{2,1}*O{2}(a)*(((O{2}(a))^2)*PP{2,1}+s(k)*(t(2)-t(1)))^(-1);
m{2}=@(a)m{1}+K{2}(a)*(x(2)-x(1)-m{1}*O{2}(a));
PP{2,2}=@(a)PP{2,1}-O{2}(a)*K{2}(a)*PP{2,1};
PP{3,2}=@(a)PP{2,2}(a)+Q(k);
m1{i+1,i}=@(a)m{i}(a);
PP{i+1,i}=@(a)PP{i,i}(a)+Q(k);
K{i+1}=@(a)PP{i+1,i}(a)*O{i+1}(a)*(((O{i+1}(a))^2)*PP{i+1,i}(a)+s(k)*(t(i+1)-t(i)))^(-1);
m{i+1}=@(a)m{i}(a)+K{i+1}(a)*(x(i+1)-x(i)-m{i}(a)*O{i+1}(a));
PP{i+1,i+1}=@(a)PP{i+1,i}(a)-O{i+1}(a)*K{i+1}(a)*PP{i+1,i}(a);
PP{i+2,i+1}=@(a)PP{i+1,i+1}(a)+Q(k);
end
a=fzero(@(a)PP{150,149}(a)-30,10)
a=fzero(@(a)m{149}(a)-30,10)
  1 comentario
Jeffrey Clark
Jeffrey Clark el 29 de Jun. de 2022
Editada: Jeffrey Clark el 29 de Jun. de 2022
@玉成, some comments about the loop:
  • O{2},m{1},m1{2,1},PP{1,1},PP{2,1},K{2},m{2},PP{2,2},PP{3,2} are reset to the same thing every loop
  • k never changes from 1
Reading the code it appears that fzero is going to call at least 600 (4 times 150) nested anonymous functions for each itteration it needs to find the root, so it may not run vary quickly. I would guess that you can expand to one function that is not a nesting of functions, but unless terms can be combined/cancelled the performance may not much better than what you did.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by