why i can't get same plot when i change Real to Im?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
Torsten
2025년 1월 24일
편집: Torsten
2025년 1월 24일
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
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
2025년 1월 24일
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)
답변 (1개)
Walter Roberson
2025년 1월 24일
이동: Walter Roberson
2025년 1월 24일
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
Walter Roberson
2025년 1월 24일
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
2025년 1월 24일
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))
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!