Wrong plot upon right calculation
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I have the next problem. Here is a code for calculation of the function K(s) with integral fun1. When s=0 the K(s)=1 at all values of parameters n,t,r1. And when I calculate it by vpa for s=0 I obtain this K=1 at all parameters. Thus, the curve K(s) must always start from the point (0,1). But when I make a plot, the curve start from some different value. Please, help me: what do I do wrong? Calculation of this integral by syms package gives right plots, but it calculates too long and I want to do it by the code below. Thank you.
clear all, close all
D=1;
n=0.01;
r1=1;
t=1;
r=(r1^2+4*t/3);
%s=0;
s=0:0.1:10;
for i = 1:length(s)
k=s(i);
fun1 = @(x)((((1-(((1-x.^2).*k.^2)/(6*r))).*besseli(0,(((1-x.^2).*k.^2)/(6*r))/2))+(((((1-x.^2).*k.^2)/(6*r))).*besseli(1,(((1-x.^2).*k.^2)/(6*r))/2))).*exp(((k.^2)/(12*r)-2*n*t).*x.^2));
f1(i,:)=integral(fun1,-1,1);
K=(exp(-k.^2/(12*r))*D*sqrt(2*n*t)/(sqrt(pi)*erf(sqrt(2*n*t))))*f1;
end
plot(s,K,'b-');
%vpa(Fun,5) % calculation of K(s,t) at certain s. At s=0 must be next K(s,t)=1

0 件のコメント
採用された回答
Star Strider
2022 年 12 月 6 日
If it needs to begin at (0,1), the only changes required are that in the ‘K’ assignment, the current value of ‘f1’ needs to be referenced specifically and ‘K’ needs to be indexed:
K(i) = (exp(-k.^2/(12*r))*D*sqrt(2*n*t)/(sqrt(pi)*erf(sqrt(2*n*t))))*f1(i);
See if those changes produce the result you want —
D=1;
n=0.01;
r1=1;
t=1;
r=(r1^2+4*t/3);
%s=0;
s=0:0.1:10;
for i = 1:length(s)
k=s(i);
fun1 = @(x)((((1-(((1-x.^2).*k.^2)/(6*r))).*besseli(0,(((1-x.^2).*k.^2)/(6*r))/2))+(((((1-x.^2).*k.^2)/(6*r))).*besseli(1,(((1-x.^2).*k.^2)/(6*r))/2))).*exp(((k.^2)/(12*r)-2*n*t).*x.^2));
f1(i,:)=integral(fun1,-1,1);
K(i)=(exp(-k.^2/(12*r))*D*sqrt(2*n*t)/(sqrt(pi)*erf(sqrt(2*n*t))))*f1(i);
end
plot(s,K,'b-');
.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interpolation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!