Re: [討論]跑完程式出現問題~~救救我~~~前一個PO錯
※ 引述《abc91633 (阿甫)》之銘言:
: 的程式跑完出現
: ??? Error using ==> feof
: Invalid file identifier. Use fopen to generate a
: valid file identifier.
: Error in ==> test_runge_kutta_main>test_runge_kutta at 110
: Error in ==> ode45 at 320
: Error in ==> test_runge_kutta_main at 74
: 請問是怎麼一回事壓???
: 我用的是matlab7.7
: 我學長用matlab6.5就不會有問題
: 可以幫我解答嗎
: 需要程式碼可以跟我說
我PO個程式碼
function result = test_runge_kutta_main(ParameterFilename)
tic;
global c epsilon_0 mu_0 q_e m_e(有一些參數)
.....(參數的值)
fid = fopen(ParameterFilename,'r');
while feof(fid) == 0
line = fgetl(fid);
eval(line);
end
.....(輸入Xi,Yi,Zi,Vxi,Vyi,Vzi)
options = odeset('Stats','on','Events',@events)
[t,X] = ode45(@test_runge_kutta, [0,tf], [Xi,Yi,Zi,Vxi,Vyi,Vzi], options);
plot3(X(:,3),X(:,1),X(:,2));
xlabel('z (meter)');
ylabel('x (meter)');
zlabel('y (meter)');
title('electron trajectory in the magnetic-bottle time of flight ');
grid on;
If X(length(X),3) < h
disp('The electron "fail" to reach the end');
elseif sqrt(X(length(X),1)^2 + X(length(X),2)^2) > rloop
disp('The electron "fail" to reach the end');
else
disp('The electron "succeeded" to reach the end');
end
toc;
function Xdot = test_runge_kutta(t, X)
global c epsilon_0 mu_0 q_e m_e
fid = fopen('trace_electron_trajectory.txt','r');
while feof(fid) == 0
line = fgetl(fid);
eval(line);
end
計算 B
Xdot = [X(4) ; X(5) ; X(6) ; q_e/m_e*(B_vector(3)*X(5) - B_vector(2)*X(6)) ; q_e/m_e*(B_vector(1)*X(6) - B_vector(3)*X(4)) ; q_e/m_e*(B_vector(2)*X(4) - B_vector(1)*X(5)) ];
disp(strcat('z=',num2str(X(3)),'/',num2str(h)));
function [value,isterminal,direction] = events(t,X)
fid = fopen('trace_electron_trajectory.txt','r');
while feof(fid) == 0
line = fgetl(fid);
eval(line);
end
value =[X(3)-h; sqrt(X(1)^2 + X(2)^2)-rloop; X(3)];
isterminal = [1; 1; 1];
direction = [0; 0; 0];
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 119.14.67.99