how to use vectorization and integral on erf function and erfc function?

Im trying to code for these equations but my math background isnt on par with this level yet. I appreciate any help on my final!
My guess would be use the values that my graph of 1-erf(z) gave me but Im not sure my graph is correct because only one of the values matched the graph erfc(z).

7 件のコメント

syms z
around = 1/2
around = 0.5000
numterm = 7
numterm = 7
matlabFunction(vpa(taylor(erfc(z), z, around, 'Order', numterm),16))
ans = function_handle with value:
@(z)z.*-8.787825789354448e-1+(z-5.0e-1).^2.*4.393912894677224e-1+(z-5.0e-1).^3.*1.464637631559075e-1-(z-5.0e-1).^4.*1.830797039448843e-1-(z-5.0e-1).^5.*7.323188157795373e-3+(z-5.0e-1).^6.*5.004178574493505e-2+9.188914116546759e-1
Henry B.
Henry B. 2021 年 5 月 27 日
so what Im gathering from your code is that in 7 terms of n the graph of erf(z)-1 and erfc(z) converge around 1/2 or .5.
and what is vpa and taylor representing. Im using octave so if they are function they may just not be available to me.
Walter Roberson
Walter Roberson 2021 年 5 月 27 日
No, the 7 was arbitrary. You should have followed the first part of the assignment to determine how many terms were needed.
taylor takes a taylor series expansion; https://www.mathworks.com/help/symbolic/sym.taylor.html . It requires the Symbolic Toolbox. The current syntax of taylor() requires R2006b or later if I recall correctly. I don't think you can purchase Symbolic Toolbox for use with Octave.
taylor() computes the coefficients exactly, such as having explicit sqrt(pi) and erf(1/2) calls. vpa() converts all such constants to their floating point equivalents.
I would suggest that you take your existing code, and run it for the same number of terms that I used (that is, 7), and see whether you get the same output as would be computed by the function handle in my comment. If you do get the same output, to within round-off error, then you know that you are on the right track. If you get significant differences then you have done something wrong in your taylor expansion code.
Henry B.
Henry B. 2021 年 5 月 27 日
編集済み: Henry B. 2021 年 5 月 27 日
this is my code for b I used 6 because that was the n output for my first code in my first question.
function [erfc2,n] = myerfc2(z)
erf1 = 0.0;
term = z;
for (n=1:6)
erf1 = erf1 + term;
n=n+1;
term = term .* (-1)/n .* z.^2 .* (2 .*n-1)./(2 .*n+1);
end
erf1 = erf1 .* 2 ./sqrt(pi);
erfc2 = 1-erf1;
end
output:
the first value appears to match but if I input 7 the smaller values get further away from the values of the function erfc(z) where z is [0.1 0.5 1 2].
Henry B.
Henry B. 2021 年 5 月 27 日
now Im just trying figure out what numerical intergration is because Im only in precalculus and have only learned first order differential which you learn in calculus 1. So my I have theorized the range of the integral is the range of z. I used 2 as the end point because for the test values of z end a 2.
function erfc3 = myerfc3(z)
efh = @(z) 1-erf(z)%create function handle for 1-erf(z)
erfc3=integral(efh,0,2)%use built in integral function
end
output:erfc3 = 0.5632
Im not sure whats the integral means or what the output value represents.
format long g
syms x
result = int(erfc(x), 0, 2)
result = 
double(result)
ans =
0.563211560832805
int(erfc(x), 0, x)
ans = 
Torsten
Torsten 2021 年 5 月 28 日
編集済み: Torsten 2021 年 5 月 28 日
@Henry:
Why do you modify my code for the calculation of erfc by prescribing n as (1:6) ? n, the number of terms needed to approximate erfc(z) within a specified tolerance, is calculated within erfc depending on the magnitude of term. For higher values of z, the n also has to increase. So first try to understand what the code does before starting to modify it.

サインインしてコメントする。

回答 (0 件)

カテゴリ

質問済み:

2021 年 5 月 27 日

編集済み:

2021 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by