How to code an equation with that integrates a vector.

조회 수: 10 (최근 30일)
MIchael
MIchael 2025년 2월 16일
답변: Torsten 2025년 2월 17일

답변 (3개)

Walter Roberson
Walter Roberson 2025년 2월 16일
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 2025년 2월 16일
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 2025년 2월 17일
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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by