필터 지우기
필터 지우기

I want to draw graph between "P" and "x" but it is throwing the following error.

조회 수: 1 (최근 30일)
syms x
alpha = -0.1;
sigma = 0.1;
eps = -0.1;
lambda = 2;
M = 4;
psi = 0.1;
a = 2;
figure
A = eps + alpha^3 + (3 * sigma^2 * alpha);
B = alpha^2 + sigma^2;
hbar = @(x) a - a.*x + x;
a1 = @(x) tanh(M .* hbar(x));
b1 = @(x) 1 - (tanh(M .* hbar(x))).^2;
c1 = (M * alpha) - ((M^3 * A)/3);
d1 = @(x) (hbar(x) .* a1(x)) + (hbar(x) .* b1(x) .* c1) + (alpha * a1(x)) + (M * B .* b1(x));
e1 = @(x) ((hbar(x).^3) .* a1(x)) + ((hbar(x).^3) .* (1 - a1(x)) .* c1) + (A *a1(x)) + (3 .* (hbar(x).^2) .*alpha .* a1(x)) + (3 .* (hbar(x).^2) .* M * B) - (3 .* (hbar(x).^2) .* M * B .* a1(x)) + (3 .* hbar(x) .*B .* a1(x)) + (3 .* hbar(x) .* b1(x) .* M * A );
f1 = 2 * (M^2) * (1 + lambda);
g1 = @(x) (3 * lambda * d1(x)) + (f1 * e1(x)) - (3 *lambda *M * B);
g2 = @(x) f1 * (a1(x) + b1(x) .* c1);
G = @(x) (1/ (2 + lambda)) .* g1(x) .* (1./g2(x));
j1 = psi/(1 + lambda);
i1 = @(x) 0.5 .* hbar(x) .* (G(x) + j1).^(-1);
I1 = @(x) integral(i1,0,x);
i2 = @(x) (G(x) + j1) .^(-1);
I2 = @(x) integral(i2,0,x);
I3 = integral(i1,0,1);
I4 = integral(i2,0,1);
D = I3 / I4;
P = @(x) I1(x) + (D * I2(x));
ylim([0 0.5])
xlim([0 1])
fplot(P(x), [1 6])
Error using integral
Limits of integration must be double or single scalars.

Error in solution (line 27)
I1 = @(x) integral(i1,0,x);

Error in solution (line 37)
P = @(x) I1(x) + (D * I2(x));

채택된 답변

Star Strider
Star Strider 2022년 7월 7일
The ‘x’ value is being used as an integration llimit, and integration limits must be scalars.
One solution is to devine the ‘x’ value as a vector, and then use arrayfun (essentially a for loop) to do the integration over the vector of limits —
% syms x
alpha = -0.1;
sigma = 0.1;
eps = -0.1;
lambda = 2;
M = 4;
psi = 0.1;
a = 2;
figure
A = eps + alpha^3 + (3 * sigma^2 * alpha);
B = alpha^2 + sigma^2;
hbar = @(x) a - a.*x + x;
a1 = @(x) tanh(M .* hbar(x));
b1 = @(x) 1 - (tanh(M .* hbar(x))).^2;
c1 = (M * alpha) - ((M^3 * A)/3);
d1 = @(x) (hbar(x) .* a1(x)) + (hbar(x) .* b1(x) .* c1) + (alpha * a1(x)) + (M * B .* b1(x));
e1 = @(x) ((hbar(x).^3) .* a1(x)) + ((hbar(x).^3) .* (1 - a1(x)) .* c1) + (A *a1(x)) + (3 .* (hbar(x).^2) .*alpha .* a1(x)) + (3 .* (hbar(x).^2) .* M * B) - (3 .* (hbar(x).^2) .* M * B .* a1(x)) + (3 .* hbar(x) .*B .* a1(x)) + (3 .* hbar(x) .* b1(x) .* M * A );
f1 = 2 * (M^2) * (1 + lambda);
g1 = @(x) (3 * lambda * d1(x)) + (f1 * e1(x)) - (3 *lambda *M * B);
g2 = @(x) f1 * (a1(x) + b1(x) .* c1);
G = @(x) (1/ (2 + lambda)) .* g1(x) .* (1./g2(x));
j1 = psi/(1 + lambda);
i1 = @(x) 0.5 .* hbar(x) .* (G(x) + j1).^(-1);
I1 = @(x) integral(i1,0,x);
i2 = @(x) (G(x) + j1) .^(-1);
I2 = @(x) integral(i2,0,x);
I3 = integral(i1,0,1);
I4 = integral(i2,0,1);
D = I3 / I4;
P = @(x) I1(x) + (D * I2(x));
xv = linspace(1, 6, 25);
Pv = arrayfun(@(x)P(x), xv);
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.6e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.6e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.7e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 2.1e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 2.1e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 8.9e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.8e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 2.1e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 9.0e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.6e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.3e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.1e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.7e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.9e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 3.2e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.4e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 2.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 8.9e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 2.6e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.1e+01. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 1.8e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is 7.7e+00. The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy.
figure
plot(xv, Pv)
% ylim([0 0.5]) % There Is Nothing To Be Plotted In This Region!
% xlim([0 1]) % There Is Nothing To Be Plotted In This Region!
xlabel('x')
ylabel('P(x)')
.

추가 답변 (1개)

Jan
Jan 2022년 7월 7일
Try:
fplot(P, [1 6]) % not P(x)

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by