why i can't get same plot when i change Real to Im?

3 vues (au cours des 30 derniers jours)
salim
salim le 24 Jan 2025
Commenté : Walter Roberson le 24 Jan 2025
i plot the real one but when i change the plot for abs i can get the abs why i can't get that of this function
0.2e1 * (0.4e1 * exp((-8 * t + 2 * x)) + 0.9e1 * exp((-27 * t + 3 * x)) + 0.25e2 * exp((-35 * t + 5 * x + 2))) / (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) - 0.2e1 * (0.2e1 * exp((-8 * t + 2 * x)) + 0.3e1 * exp((-27 * t + 3 * x)) + 0.5e1 * exp((-35 * t + 5 * x + 2))) ^ 2 / (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) ^ 2
and my code for ploting is
abs(0.2e1 .* (0.4e1 * exp((-8 * t + 2 * x)) + 0.9e1 .* exp((-27 * t + 3 * x)) + 0.25e2 .* exp((-35 * t + 5 * x + 2))) ./ (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) - 0.2e1 * (0.2e1 .* exp((-8 * t + 2 * x)) + 0.3e1 .* exp((-27 * t + 3 * x)) + 0.5e1 .* exp((-35 * t + 5 * x + 2))) .^ 2 ./ (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 .* x)) + exp((-35 * t + 5 * x + 2))) .^ 2).^2
  2 commentaires
Torsten
Torsten le 24 Jan 2025
Modifié(e) : Torsten le 24 Jan 2025
I can't see a difference:
f = @(x,t) 0.2e1 * (0.4e1 * exp((-8 * t + 2 * x)) + 0.9e1 * exp((-27 * t + 3 * x)) + 0.25e2 * exp((-35 * t + 5 * x + 2))) / (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) - 0.2e1 * (0.2e1 * exp((-8 * t + 2 * x)) + 0.3e1 * exp((-27 * t + 3 * x)) + 0.5e1 * exp((-35 * t + 5 * x + 2))) ^ 2 / (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) ^ 2
f = function_handle with value:
@(x,t)0.2e1*(0.4e1*exp((-8*t+2*x))+0.9e1*exp((-27*t+3*x))+0.25e2*exp((-35*t+5*x+2)))/(exp(0.2e1)+exp((-8*t+2*x))+exp((-27*t+3*x))+exp((-35*t+5*x+2)))-0.2e1*(0.2e1*exp((-8*t+2*x))+0.3e1*exp((-27*t+3*x))+0.5e1*exp((-35*t+5*x+2)))^2/(exp(0.2e1)+exp((-8*t+2*x))+exp((-27*t+3*x))+exp((-35*t+5*x+2)))^2
x = -20:0.1:20;
t = -4:0.1:4;
for i = 1:numel(x)
for j = 1:numel(t)
p(i,j) = f(x(i),t(j));
end
end
figure()
surf(x,t,p.','Edgecolor','none')
figure()
surf(x,t,abs(p.'),'Edgecolor','none')
From the title of your plots, it seems that the name of an array you use is "abs" ? If so, rename it.
Walter Roberson
Walter Roberson le 24 Jan 2025
In Maple, map(abs,solnum) applies the function abs to the elements of solnum one by one. It is more or less equivalent to MATLAB's arrayfun(@abs, solnum)

Connectez-vous pour commenter.

Réponses (1)

Walter Roberson
Walter Roberson le 24 Jan 2025
Déplacé(e) : Walter Roberson le 24 Jan 2025
You are plotting in Maple. MATLAB returns correct results.
syms x t
map(x,t) = 0.2e1 * (0.4e1 * exp((-8 * t + 2 * x)) + 0.9e1 * exp((-27 * t + 3 * x)) + 0.25e2 * exp((-35 * t + 5 * x + 2))) / (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) - 0.2e1 * (0.2e1 * exp((-8 * t + 2 * x)) + 0.3e1 * exp((-27 * t + 3 * x)) + 0.5e1 * exp((-35 * t + 5 * x + 2))) ^ 2 / (exp(0.2e1) + exp((-8 * t + 2 * x)) + exp((-27 * t + 3 * x)) + exp((-35 * t + 5 * x + 2))) ^ 2;
fsurf(real(map), [-20 20 -5 5])
fsurf(imag(map), [-20 20 -5 5])
fsurf(abs(map), [-20 20 -5 5])
  3 commentaires
Walter Roberson
Walter Roberson le 24 Jan 2025

All values produced by the function are already real values that are non-negative. The absolute value is therefore the same as the original values

Walter Roberson
Walter Roberson le 24 Jan 2025
If solnum is the formula then when you map(abs, solnum) then you are applying abs() to the pieces of the formula rather than to the overall result of the formula.
Now, it looks to me as if each of the pieces of the formula should already be positive, but just maybe the map() is doing something like converting exp((-8 * t + 2 * x)) to exp(abs(-8 * t + 2 * x))

Connectez-vous pour commenter.

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by