Error in using Integration, How to fix it ?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Farah Jwaifel
am 12 Jan. 2021
Bearbeitet: Alan Stevens
am 12 Jan. 2021
I am trying to plot a function with integration in it, and it always gives me an error in using the integral, I tried using function handle for the first argument (according to the error) , but the error remaind.
t = 0:0.02:20;
y = 0:1000;
x = @(t,y) (y/((4*t*0.02/1000)^0.5));
fun = @(x)(exp(-x.^2));
erf = (2/pi^(0.5)) *integral(fun,0,x); % the error is in this line
erfc= 1 - erf;
VProfile= 10*erfc;
plot(t,VProfile)
title('Velocity Profile')
xlabel('time (sec)')
ylabel('Velocity (cm/sec)')
so what did I do wrong? and how can I fix it ? and if the code has another error I didnt notice, please point it out.
thank you.
0 Kommentare
Akzeptierte Antwort
Alan Stevens
am 12 Jan. 2021
Bearbeitet: Alan Stevens
am 12 Jan. 2021
Since x has t in the denominator. t=0 will cause problems, so start at t = 0.02 instead, perhaps! This would require a change in y to get the same number of elements as t.
You don't need x as a function. Replace with
x = y./((4*t*0.02/1000).^0.5);
then calculate your error function in a loop:
for i = 1:numel(t)
erf(i) = (2/pi^(0.5))*integral(fun,0,x(i));
end
Best not to use erf and erfc as they are functions already built-in to MATLAB. Better as, say, erF and erFc.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Calculus finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!