How to code an equation with that integrates a vector.

5 vues (au cours des 30 derniers jours)
MIchael
MIchael le 16 Fév 2025
Réponse apportée : Torsten le 17 Fév 2025

Réponses (3)

Walter Roberson
Walter Roberson le 16 Fév 2025
There are two ways.
You can do it symbolically:
syms A B C
syms u__vec_(t) [1 5]
x_0__vec = [A*cos(B)*cos(C)
5 + A*sin(B)
A*cos(B)*sin(C)];
x__vec = x_0__vec + int(u__vec_, t, 0, t)
x__vec = 
Or you can do it numerically
An = 1.2; Bn = pi/8; Cn = 2*pi/5;
x0_vec = [An*cos(Bn)*cos(Cn)
5 + An*sin(Bn)
An*cos(Bn)*sin(Cn)];
tn = 5;
u_vec = @(t) [t.^2/5, exp(-t), sqrt(t)];
x_vec = x0_vec + integral(u_vec, 0, tn, 'arrayvalued', true)
x_vec = 3×3
8.6759 1.3359 7.7962 13.7926 6.4525 12.9128 9.3877 2.0477 8.5080
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Note that in the numeric case, you must define a specific numeric upper-bound for the integration.

Star Strider
Star Strider le 16 Fév 2025
Siince ‘u’ is also a vector —
u = @(t) [sinh(t); cosh(t); tanh(t)]
u = function_handle with value:
@(t)[sinh(t);cosh(t);tanh(t)]
int_u = integral(u, 0, 1, ArrayValued=true)
int_u = 3×1
0.5431 1.1752 0.4338
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
A = rand
A = 0.9710
B = rand
B = 0.3265
C = rand
C = 0.6471
x0 = [A.*cos(B).*cos(C); 5+A*sin(B); A.*cos(A).*sin(C)]
x0 = 3×1
0.7338 5.3114 0.3304
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
xv = x0 + integral(u, 0, 1, ArrayValued=true)
xv = 3×1
1.2768 6.4867 0.7642
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Make appropriate changes to ‘u’ and the constants to get the result you want.
.

Torsten
Torsten le 17 Fév 2025
If there is no closed-form expression for u (e.g. if u depends on x), you can solve the vector-differential equation
dx/dt = u
x(0) = x0

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by