How can find t?
이전 댓글 표시
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개)
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.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!