Filter löschen
Filter löschen

How to use loop to reduce the code?

1 Ansicht (letzte 30 Tage)
Guan-Lin Chen
Guan-Lin Chen am 24 Nov. 2020
Beantwortet: Setsuna Yuuki. am 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!

Akzeptierte Antwort

Setsuna Yuuki.
Setsuna Yuuki. am 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;

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by