简体   繁体   English

MATLAB 中的 Ode45

[英]Ode45 in MATLAB

I'm quite new to MATLAB and im trying to integrate two functions using the ode45() function.我对 MATLAB 很ode45() ,我正在尝试使用ode45()函数集成两个函数。 My code:我的代码:

[w,x] = ode45( @(w,x) ( TSII - TFII ) * w , [0 2], 0 );

Where TSII and TFII are column vectors 1x151 containing the values of my two functions.TSIITFII是包含我的两个函数值的列向量1x151。 w does not have any value yet, but I've tried making it a column vector full of zeroes length 1x151 and that did not solve my problem. w还没有任何值,但我已经尝试将其设置为一个长度为 1x151 的零的列向量,但这并没有解决我的问题。

I get the following error message:我收到以下错误消息:

@(W,X)(TSII-TFII)*W returns a vector of length 151, but the length of initial conditions vector is 1 . @(W,X)(TSII-TFII)*W returns a vector of length 151, but the length of initial conditions vector is 1

The vector returned by @(W,X)(TSII-TFII)*W and the initial conditions vector must have the same number of elements. @(W,X)(TSII-TFII)*W返回的向量和初始条件向量必须具有相同数量的元素。

Is it possible to change the initial conditions vector to the same length as TSII and TFII ?是有可能的初始条件矢量改变为相同的长度TSIITFII

Or, should I use a loop with ode45() inside to make the 151 values?或者,我应该使用内部包含ode45()的循环来生成 151 个值吗?

I am guessing a bit, but give it a try:我有点猜测,但试一试:

ode45() would like your anonymous function @(w,x) to interpolate the function value at position x . ode45()希望您的匿名函数@(w,x)在位置x插入函数值。 If TSII and TFII are tabular function values as you write, it will not return the expected result.如果 TSII 和 TFII 是您编写的表格函数值,则不会返回预期结果。

You should use something like interp1(TSII,x) instead of TSII .你应该使用类似interp1(TSII,x)而不是TSII your function should look like:您的函数应如下所示:

@(w,x) ( interp1(TSII,x) - interp1(TFII,x) ) .* w

Also note the .* for the element wise multiplication.还要注意.*用于元素乘法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM