How can find t?
Afficher commentaires plus anciens
I did my homework to solve a problem with Heun's method. Thing is, I want to show the value of t(my x-axis) when v=0, with "index= find(v==0)" doesn't work... How can i find my value of t? in this program?
% Método de Heun
clear all
clc
a= 0; b= 20;
n= 40; v0= 300; h = (b - a) / n;
v(1,:) = v0; t(1) = a;
f= @(t,v) -0.0035*v^2 -3
for i = 1 : n
t(i+1) = t(i) + h
g = f(t(i),v(i,:))
z = v(i,:) + h * g
v(i+1,:) = v(i,:) + h/2 * ( g + f(t(i+1),z) )
end;
plot(t, v)
whitebg('k')
title('V vs T, dy/dx= -0.0035v²-3', 'Fontsize', 18)
xlabel('Tiempo', 'Fontsize', 16)
ylabel('Velocidad', 'Fontsize', 16)
find(y==10)
Réponses (1)
Star Strider
le 15 Fév 2015
Modifié(e) : Star Strider
le 15 Fév 2015
I did not run your code, but your way of finding the value of the index of ‘t’ where ‘v’ crosses zero is almost correct.
See if:
index1 = find(v<=0, 1, 'first');
or:
index2 = find(v>=0, 1, 'last');
brings you closer to what you want. Those indices should be below and above the indices of the value of ‘t’ for which ‘v’ crosses zero.
You have to deal with inexact numeric representations that are part of floating-point arithmetic, as well as your velocity variable not being exactly zero in your calculations.
Note: your function has to have at least one zero-crossing for this to work.
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!