How can find t?

4 次查看(过去 30 天)
Gimmy Morales
Gimmy Morales 2015-2-15
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 个评论
Gimmy Morales
Gimmy Morales 2015-2-15
% % 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]

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2015-2-15
编辑:Star Strider 2015-2-15
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.

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by