Borrar filtros
Borrar filtros

How can find t?

11 visualizaciones (últimos 30 días)
Gimmy Morales
Gimmy Morales el 15 de Feb. de 2015
Editada: Star Strider el 15 de Feb. de 2015
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)
  1 comentario
Gimmy Morales
Gimmy Morales el 15 de Feb. de 2015
% % 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);
t=t';
twv0=[t v]

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 15 de Feb. de 2015
Editada: Star Strider el 15 de Feb. de 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.

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by