You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MATLAB求解含积分的方程时出现Empty sym:0-by-1错误求助

Hey there! Let's break down why you're hitting that Empty sym: 0-by-1 error and fix your MATLAB code to solve the equation properly.

What's Causing the Error?

That error means vpasolve can't find a valid solution to your equation, and the root cause is how you're mixing symbolic and numerical functions here:

  • normcdf and normpdf are numerical statistical functions, not fully compatible with MATLAB's symbolic integration (int). The symbolic toolbox can't compute an analytical closed-form for your integral, leaving eqn as an incomplete expression that vpasolve can't process.

How to Fix It: Switch to Numerical Methods

Since your equation involves a non-analytical integral, numerical solvers like fzero are a better fit. Here's a step-by-step corrected approach:

  1. Define a numerical function that calculates the left-hand side of your equation for any given x (using numerical integration instead of symbolic).
  2. Visualize the function to find a rough guess of where it crosses zero (critical for fzero to work).
  3. Use fzero to find the exact root.

Corrected Code

a = 0.2; 
b = 10; 
c = -10; 
d = 15; 
mu = 3; 
sig = 1;

% Define the numerical function for your equation
f = @(x) a + b*normcdf(x, mu, sig) + c*integral(@(t) normcdf(d + x - t, mu, sig).*normpdf(t, mu, sig), 0, x);

% Plot the function to find a valid initial guess for x
x_vals = linspace(-5, 10, 100);
y_vals = arrayfun(f, x_vals);

figure;
plot(x_vals, y_vals, 'LineWidth', 1.5);
hold on;
plot(x_vals, zeros(size(x_vals)), 'k--', 'LineWidth', 1);
xlabel('x'); ylabel('f(x)');
title('f(x) = 0: Find Where the Line Crosses Zero');
hold off;

% Solve using fzero (use a guess from the plot, e.g., x0=5)
x_solution = fzero(f, 5);
fprintf('Solution: x = %.4f\n', x_solution);

Key Notes

  • The integral function handles the numerical integration cleanly, pairing with normcdf/normpdf without symbolic conflicts.
  • Always plot the function first! If you pick a bad initial guess for fzero, it might fail or return an incorrect root. From the plot, you can see exactly where f(x) crosses zero.
  • If you run into integration warnings, add 'ArrayValued', true to the integral call to handle vector inputs more robustly.

内容的提问来源于stack exchange,提问作者Mike Lang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:33:21