Summation function with two variables concentration profile
5 次查看(过去 30 天)
显示 更早的评论
Hi,
Need some help plotting the attached equation For some reason my plot is not oming out as needed. For example, I want to be able to plot C vs X for this equation. For some reason my methodology doesn't com out right

D=1.79e-5;
C1=0.79;
C0=0;
x=linspace(-60,60,1000);
n=linspace(0,.020,1000);
t=linspace(0,1,1000);
xs=linspace(0,120,100);
ax1=(4./pi()).*(((-1).^n)./(2.*n+1));
bx1=exp(-((D*((2*n+1).^2)*(pi().^2).*t)./(4.*l.^2)));
cx1=cos(((2.*n+1).*pi().*x)./(2.*l));
CC1=C0+(C1-C0).*(1-ax1.*bx1.*cx1);
figure(1)
plot(xs,CC1,'-k')
0 个评论
采纳的回答
Walter Roberson
2022-4-2
D=1.79e-5;
C1=0.79;
C0=0;
l = 120/2;
x=linspace(-l,l,1000);
n=linspace(0,.020,1000).';
t=linspace(0,1,1000).';
ax1=(4./pi()).*(((-1).^n)./(2.*n+1));
bx1=exp(-((D*((2*n+1).^2)*(pi().^2).*t)./(4.*l.^2)));
cx1=cos(((2.*n+1).*pi().*x)./(2.*l));
CC1=C0+(C1-C0).*(1-ax1.*bx1.*cx1);
figure(1)
whos
figure
surf(x, t, real(CC1), 'edgecolor', 'none')
title('real CC1')
figure
surf(x, t, imag(CC1), 'edgecolor', 'none')
title('imag CC1')
9 个评论
Walter Roberson
2022-4-2
You can evaluate over a range of values of n and sum() afterwards.
But what precision do you need? Although the calculation does appear to converge (perhaps I should have checked more carefully) the third digit is still changing when you take a million terms -- the terms might be small but they add up in bulk.
Walter Roberson
2022-4-2
Do you have a fix for that?
No, I do not have a fix for that. I do not think you are calculating the correct thing.
For a calculation like this, every independent variable that is being varied over should have its own axes. x should be a different axes than t which should be a different axes than n. You would typically calculate for a finite number of n and then sum() over that axes, giving you a result that has x and t and possibly other axes. Once you have the multi-dimensional output you would try to summarize it into plots.
Because your x and t are different continuous independent axes, your plot should not be trying to drop t on the output.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





