0% found this document useful (0 votes)
13 views6 pages

Code

Uploaded by

Phúc Khang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

Code

Uploaded by

Phúc Khang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

function varargout = BTLnhom3(varargin)

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @BTLnhom3_OpeningFcn, ...

'gui_OutputFcn', @BTLnhom3_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

global m v0 h timeEnd;

function BTLnhom3_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

function varargout = BTLnhom3_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function m_text_Callback(hObject, eventdata, handles)

global m;

m = str2double(get(handles.m_text,'String'));
function m_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function v0_text_Callback(hObject, eventdata, handles)

global v0;

v0 = str2double(get(handles.v0_text,'String'));

function v0_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function alpha_text_Callback(hObject, eventdata, handles)

global gocnem;

gocnem = str2double(get(handles.alpha_text,'String'));

function alpha_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function h_text_Callback(hObject, eventdata, handles)

global h;

h = str2double(get(handles.h_text,'String'));

function h_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end
function t_text_Callback(hObject, eventdata, handles)

global timeEnd;

timeEnd = str2double(get(handles.t_text,'String'));

function t_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function pushbutton1_Callback(hObject, eventdata, handles)

syms t a;

global m v0 gocnem h timeEnd;

g=-9.8;

a = deg2rad(gocnem);

t_total = linspace(0,timeEnd,100);

x(t)=dsolve('D2x+(h/m)*Dx=0','x(0)=0','Dx(0)=v0*cos(a)');

y(t)=dsolve('D2y+(h/m)*Dy-g=0','y(0)=0','Dy(0)=v0*sin(a)');

xExpr=subs(x(t));

yExpr=subs(y(t));

x=double(subs(xExpr, t, t_total));

y=double(subs(yExpr, t, t_total));

axes(handles.dothi);

xlabel('xExpr');

ylabel('yExpr');

grid on;

xlim([min(x)-10, max(x)+10]);

ylim([min(y)-10, max(y)+10]);

for i = 1:length(t_total)

set(handles.x_text, 'String', num2str(round(x(i),2)), 'FontSize', 10);

set(handles.y_text, 'String', num2str(round(y(i),2)), 'FontSize', 10);


set(handles.time_text, 'String', num2str(round(t_total(i),2)), 'FontSize', 10);

axes(handles.dothi);

hold off;

plot(x(1:i),y(1:i),'b--','LineWidth',1);

hold on;

scatter(x(i),y(i),100,'r','filled');

hold off;

xlim([min(x)-10, max(x)+10]);

ylim([min(y)-10, max(y)+10]);

grid on;

pause (0.001);

end

function x_text_Callback(hObject, eventdata, handles)

function x_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function y_text_Callback(hObject, eventdata, handles)

function y_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function time_text_Callback(hObject, eventdata, handles)

function time_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');
end

function pushbutton2_Callback(hObject, eventdata, handles)

syms t a al;

global m v0 h timeEnd;

g=-9.8;

t_total = linspace(0,timeEnd,100);

x(t)=dsolve('D2x+(h/m)*Dx=0','x(0)=0','Dx(0)=v0*cos(a)');

y(t)=dsolve('D2y+(h/m)*Dy-g=0','y(0)=0','Dy(0)=v0*sin(a)');

xExpr=subs(x(t));

yExpr=subs(y(t));

for p = 1:5

hold on

str = string(p*15);

al = deg2rad(p*15);

xa=subs(xExpr, a, al);

ya=subs(yExpr, a, al)

x=double(subs(xa, t, t_total));

y=double(subs(ya, t, t_total));

axes(handles.dothi1);

xlabel('xa');

ylabel('ya');

grid on;

xlim([min(x)-10, max(x)+10]);

ylim([min(y)-10, max(y)+10]);

for i = 1:length(t_total)

axes(handles.dothi1);

hold on;

plot(x(1:i),y(1:i),'LineWidth',1);
hold off;

xlim([min(x)-10, max(x)+10]);

ylim([min(y)-10, max(y)+10]);

grid on;

pause (0.00001);

end

end

function xt_text_Callback(hObject, eventdata, handles)

function xt_text_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function yt_text_Callback(hObject, eventdata, handles)

function yt_text_CreateFcn(hObject, eventdata, handles)

function Action_Callback(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

You might also like