필터 지우기
필터 지우기

How can find t?

조회 수: 11 (최근 30일)
Gimmy Morales
Gimmy Morales 2015년 2월 15일
편집: Star Strider 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에서 Just for fun에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by