Integral of equation with vectors

1 次查看(过去 30 天)
clc; clear all;
%%Test of Intergral
t = (0:0.5:8); % Timestep and interval
h = 10; % Water height
H = 4; % Wave height
a = [0 -0.7 -1.4 -1.8 -2.0 -1.9 -1.5 -0.9 -0.2 0.5 1.1 1.6 1.9 1.9 1.6 1.1 0.4]; % accelerations
u = [2.6 2.4 1.9 1.1 0.1 -0.8 -1.6 -2.3 -2.6 -2.5 -2.1 -1. -0.4 0.5 1.4 2.1 2.5]; % Velocity
D = 2; % Diameter
syms x
f(x) = pi.*(D/2)^2.*x.*a+1/2.*u.*abs(u).*D.*x; % My Function
p = arrayfun(@(x)integral(f(x),0,10)); %<--- first try integral this from the range of 0 to 10
g(x) = integral(f,0,10); %<-- need to integral this from the range of 0 to 10

采纳的回答

Andrei Bobrov
Andrei Bobrov 2016-2-29
编辑:Andrei Bobrov 2016-2-29
h = 10;
H = 4;
a = [0 -0.7 -1.4 -1.8 -2.0 -1.9 -1.5 -0.9 -0.2 0.5 1.1 1.6 1.9 1.9 1.6 1.1 0.4];
u = [2.6 2.4 1.9 1.1 0.1 -0.8 -1.6 -2.3 -2.6 -2.5 -2.1 -1. -0.4 0.5 1.4 2.1 2.5];
D = 2;
f = @(x,a,u) pi.*(D/2)^2.*x.*a+1/2.*u.*abs(u).*D.*x;
p = arrayfun(@(a,u)integral(@(x)f(x,a,u),0,10),a,u);
or try
h = 10;
H = 4;
a = [0 -0.7 -1.4 -1.8 -2.0 -1.9 -1.5 -0.9 -0.2 0.5 1.1 1.6 1.9 1.9 1.6 1.1 0.4];
u = [2.6 2.4 1.9 1.1 0.1 -0.8 -1.6 -2.3 -2.6 -2.5 -2.1 -1. -0.4 0.5 1.4 2.1 2.5];
D = 2;
f = @(x) pi.*(D/2)^2.*x.*a+1/2.*u.*abs(u).*D.*x;
p = integral(f,0,10,'ArrayValued',true);
  2 个评论
Mikkel
Mikkel 2016-2-29
It works, thanks. But can you explain why the 'ArrayValued',true <-- what it does?

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2016-2-29
a = [0 -0.7 -1.4 -1.8 -2.0 -1.9 -1.5 -0.9 -0.2 0.5 1.1 1.6 1.9 1.9 1.6 1.1 0.4]; % accelerations
u = [2.6 2.4 1.9 1.1 0.1 -0.8 -1.6 -2.3 -2.6 -2.5 -2.1 -1. -0.4 0.5 1.4 2.1 2.5]; % Velocity
D = 2; % Diameter
fun=@(x,a,u,D) pi.*(D/2)^2.*x.*a+1/2.*u.*abs(u).*D.*x;
p=integral(@(x)fun(x,a,u,D),0,10,'ArrayValued',true);
Best wishes
Torsten.

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by