float point freezing matlab
Mostrar comentarios más antiguos
I Believe I need to increase the float-point precision to get and accurate graph, but matlab feezes. Vl should have a large spike at 0, .07, &.12 , albeit for a very small amount of time. Is it possible to maniplulate the polt to show this spike?
clc;
syms ig(t) il2(t) vl(t) 'r';
e=exp(1);
ig(t) = piecewise(t<0,1,0<=t<=.070,3,.070<=t<=.120,6,.120<=t,2);
il2(t) = piecewise(t<=0,0.83,0<=t<=.070,2.5-1.67*exp(-1.2*(10^(7))*t),.070<=t<=.120,5-2.5*exp(-1.2*(10^(7))*(t-.070)),.120<=t,1.67+3.33*exp(-1.2*(10^(7))*(t-.120)));
vl(t) = piecewise(t<=0,0,0<=t<=.070,20040*exp(-1.2*(10^(7))*t),.07<=t<=.120,30000*exp(-1.2*(10^7)*(t-.07)),.120<=t,-39960*exp(-12*(10^7)*(t-.12)));
t=-.10:1e-6:.200;
step=ig(t);
current2=il2(t);
voltage=vl(t);
subplot(3,1,1);
plot(t,step,'linewidth',1);
grid on;
xlim([-.010 .200])
ylim([-1 10])
xlabel('time(s)');
ylabel('ig(A)');
title('EECS 215 HW 7.6')
subplot(3,1,2);
plot(t,current2,'linewidth',1);
grid on;
xlim([-.010 .200])
ylim([-1 10])
xlabel('time(s)');
ylabel('iL(A)');
subplot(3,1,3);
plot(t,voltage,'linewidth',1);
grid on;
xlim([-.0010 .130])
ylim([-1 30000])
xlabel('time(s)');
ylabel('vl(V)');
Respuestas (1)
Star Strider
el 17 de Mzo. de 2021
I edited the functions to be anonymous functions so the code no longer takes forever. However, there are significant problems, since large portions of the function outputs are NaN. indicating 0/0, Inf/Inf or similar problems. I followed the initial piecewise functions exactly (or so it appears), so you will likely have to troubleshoot those to see what the problems are. Understanding the anonymous function construction should be straightforward.
% syms ig(t) il2(t) vl(t) 'r';
%
% e=exp(1);
%
% ig(t) = piecewise(t<0,1,0<=t<=.070,3,.070<=t<=.120,6,.120<=t,2);
% il2(t) = piecewise(t<=0,0.83,0<=t<=.070,2.5-1.67*exp(-1.2*(10^(7))*t),.070<=t<=.120,5-2.5*exp(-1.2*(10^(7))*(t-.070)),.120<=t,1.67+3.33*exp(-1.2*(10^(7))*(t-.120)));
% vl(t) = piecewise(t<=0,0,0<=t<=.070,20040*exp(-1.2*(10^(7))*t),.07<=t<=.120,30000*exp(-1.2*(10^7)*(t-.07)),.120<=t,-39960*exp(-12*(10^7)*(t-.12)));
ig = @(t) 1.*(t<0) + ((0<=t) & (t<=.070)).*3 + ((.070<=t) & (t<=.120)).*6 + (.120<t).*2;
il2 = @(t) (t<=0).*0.83 + ((0<=t) & (t<=.070)).*(2.5-1.67.*exp(-1.2E7.*t)) + ((.07<=t) & (t<=.120)).*(5-2.5.*exp(-1.2E7.*(t-.070))) + (.120<=t).*(1.67+3.33.*exp(-1.2E7).*(t-.120));
vl = @(t) (t<=0).*0 + ((0<=t) & (t<=.070)).*(20040.*exp(-1.2E7.*t)) + ((.070<=t) & (t<=.120)).*(30000.*exp(-1.2E7.*(t-.07))) + (.120<=t).*(-39960.*exp(-1.2E7.*(t-.12)));
t=-.10:1e-6:.200;
step=ig(t);
current2=il2(t);
voltage=vl(t);
subplot(3,1,1);
plot(t,step,'linewidth',1);
grid on;
xlim([-.010 .200])
ylim([-1 10])
xlabel('time(s)');
ylabel('ig(A)');
title('EECS 215 HW 7.6')
subplot(3,1,2);
plot(t,current2,'linewidth',1);
grid on;
xlim([-.010 .200])
ylim([-1 10])
xlabel('time(s)');
ylabel('iL(A)');
subplot(3,1,3);
plot(t,voltage,'linewidth',1);
grid on;
xlim([-.0010 .130])
% ylim([-1 30000])
xlabel('time(s)');
ylabel('vl(V)');
.
Categorías
Más información sobre Beamforming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!