我正在尝试为我的微分方程课解决这个作业,但遇到了一些问题。
鉴于此 ODE 系统:
dy(1) = y(2) − y(3);
dy(2) = −3*y(2) − 5*sin(ω*y(1));
dy(3) = y(1)*y(2);
与omega=3
. 初始值:y(1)=0; y(2)=4; y(3)=1;
在和f
之间绘制:t=0
t=20
f(t) = |2*cos(y1(t)) + y2(t)|
我首先尝试使用以下代码使用 ODE45 模拟方程组:
在编辑器上:
function dy=modelo10(t,y)
global omega
dy = zeros(3,1);
dy(1)= y(2) - y(3);
dy(2)= -3*y(2) - 5*sin(omega*y(1));
dy(3)= y(1)*y(2);
end
在命令选项卡上:
>>global omega;
>>omega = 3;
>>[T,Y] = ode45(@modelo10, [0,20], [0,4,1]);
%% I assign the function to variable f
>>f = @(t) 2.*cos(y(:,1)) + y(:,2);
%% And finally plot it with the values t
>>fplot(f, [0,20]);
我得到一个带有以下错误的空白图表:
Warning: Function behaves unexpectedly on array inputs. To improve
performance, properly
vectorize your function to return an output with the same size and
shape as the input
arguments.
In matlab.graphics.function.FunctionLine>getFunction
In matlab.graphics.function.FunctionLine/updateFunction
In matlab.graphics.function.FunctionLine/set.Function_I
In matlab.graphics.function.FunctionLine/set.Function
In matlab.graphics.function.FunctionLine
In fplot>singleFplot (line 241)
In fplot>@(f)singleFplot(cax,{f},limits,extraOpts,args) (line 196)
In fplot>vectorizeFplot (line 196)
In fplot (line 166)
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in
FunctionLine update:
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Warning: Error updating FunctionLine.
The following error was reported evaluating the function in
FunctionLine update:
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false
所以我的问题是要绘制的步骤(或命令)是什么f
?
我正在使用 MATLAB R2019a。