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

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 Comments

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.
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)

Sign in to comment.

Answers (1)

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 Comments

@Walter Roberson is intresting for me why two different result is coming out from one function the abs is so different from matlab i am confusing which one is correct maple or matlab

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

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))

Sign in to comment.

Products

Release

R2021b

Asked:

on 24 Jan 2025

Commented:

on 24 Jan 2025

Community Treasure Hunt

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

Start Hunting!