恒Λn 2022-08-18 00:16 采纳率: 100%
浏览 2445
已结题

MATLAB报错输入参数过多,如何解决?

MATLAB用ode45求解一阶常微分方程时,提示句柄使用错误,输入参数过多

clear
clc
x = linspace(- pi / 2 , pi / 2 , 100);
y1 = 0.5 * atan(x) .^ 2 + 1;

syms ys(xs);
equs = diff(ys , xs) == atan(xs) / (xs ^ 2 + 1);
conds = ys(0) == 1;
y2 = dsolve(equs , conds);
y2 = subs(y2 , 'xs' , x);

yh = @(xh) atan(xh) ./ (xh .^ 2 + 1);
yh0 = 1;
[x3 , y3] = ode45(yh , x , yh0);

figure
plot(x , y1 , 'o' , x , y2 , 'x' , x , y3 , 's')
legend('analytic solution' , 'dsolve method' , 'ode45 method')

运行结果及报错内容:

错误使用 test0_14_1>@(xh)atan(xh)./(xh.^2+1)
输入参数太多。

出错 odearguments (第 90 行)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.

出错 ode45 (第 106 行)
  odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);

出错 test0_14_1 (第 14 行)
[x3 , y3] = ode45(yh , x , yh0);

我之前使用ode45函数,格式和这次一模一样, 全都能成功运行,没有报错,就这次突然这样

特此请教

  • 写回答

1条回答 默认 最新

  • 生途南北 2022-08-18 13:21
    关注

    第12行替换为 yh = @(xh,y) atan(xh) ./ (xh .^ 2 + 1);即可
    其中y是对应y3的结果
    (望采纳)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 8月26日
  • 已采纳回答 8月18日
  • 创建了问题 8月18日

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样