How to use loop to reduce the code?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Guan-Lin Chen
le 24 Nov 2020
Réponse apportée : Setsuna Yuuki.
le 24 Nov 2020
clc
clear
syms t sigma
r = -4;
w = 2;
a = 1;
b = 1;
W = 1;
A_sin = 1;
A_sigma = [0,1;
-w^2,-a*((A_sin*sin(W*sigma)^2)/w^4)-b*x_2+r];
A_1 = int((A_sigma),sigma, 0, t) ;
A_2 = int((A_sigma*A_1),sigma, 0, t);
A_3 = int((A_sigma*A_2),sigma, 0, t);
A_4 = int((A_sigma*A_3),sigma, 0, t);
A_5 = int((A_sigma*A_4),sigma, 0, t);
phi = [1 0; 0 1]+ A_1+A_2+A_3+A_4+A_5;
The code I have is to integrate 5 times
How to write the for loop so that I can intergrate for 1000 times
Thank you!
0 commentaires
Réponse acceptée
Setsuna Yuuki.
le 24 Nov 2020
you can try with cell
clc
clear
syms t sigma
r = -4;
w = 2;
a = 1;
b = 1;
W = 1;
x_2 = 1
A_sin = 1;
A_sigma = [0,1;-w^2,-a*((A_sin*sin(W*sigma)^2)/w^4)-b*x_2+r];
B=0;
A{1} = int((A_sigma),sigma, 0, t);
for n = 2:5
A{n} = int((A_sigma*A{n-1}),sigma, 0, t);
B = A{n}+B;
end
phi = [1 0; 0 1]+A{1}+B;
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!