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

1 visualizzazione (ultimi 30 giorni)
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));

Risposta accettata

Star Strider
Star Strider il 7 Lug 2022
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)')
.

Più risposte (1)

Jan
Jan il 7 Lug 2022
Try:
fplot(P, [1 6]) % not P(x)

Categorie

Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by