How to use loop to reduce the code?

1 visualización (últimos 30 días)
Guan-Lin Chen
Guan-Lin Chen el 24 de Nov. de 2020
Respondida: Setsuna Yuuki. el 24 de Nov. de 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!

Respuesta aceptada

Setsuna Yuuki.
Setsuna Yuuki. el 24 de Nov. de 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;

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by