I want to draw graph between "P" and "x" but it is throwing the following error.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
AVINASH SAHU
le 7 Juil 2022
Commenté : AVINASH SAHU
le 7 Juil 2022
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])
0 commentaires
Réponse acceptée
Star Strider
le 7 Juil 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);
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)')
.
0 commentaires
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!