MATLAB: I’m a noob and can someone simplify this. I’m trying to make one vector R and one i equation.

arrayhelpMATLABnoobsimplifyvector

t=[0:0.1:4]; %times from 0 to 4s with intervals of 0.1
%R=[4,3,2,1,0.5] not working
R1=4;
R2=3;
R3=2;
R4=1;
R5=0.5;
L=2;
i1=10-2*exp((-R1/L)*t)
i2=10-2*exp((-R2/L)*t)
i3=10-2*exp((-R3/L)*t)
i4=10-2*exp((-R4/L)*t)
i5=10-2*exp((-R5/L)*t)
%[i1,i2,i3,i4,i5]=10-2*exp((-R/L)*t) not working
figure('name','Cap Circuit');
plot(t,i1,'o',t,i2,'+',t,i3,'*',t,i4,'.',t,i5,'LineWidth',3')
title('Cap Circuit')
xlabel('Time (s)')
ylabel('Current (A)')
legend('show',{'4 ohms','3 ohms','2 ohms','1 ohms','0.5 ohms'})

Best Answer

Use ordinary vector multiplication to automatically do the multiplication, then take the exp of that matrix to produce the following plot:
t=[0:0.1:4]; %times from 0 to 4s with intervals of 0.1
R=[4,3,2,1,0.5];
L=2;
iv = exp(-R(:)/L * t); % The ‘i’ Values Matrix
figure('name','Cap Circuit');
plot(t,iv,'LineWidth',3')
title('Cap Circuit')
xlabel('Time (s)')
ylabel('Current (A)')
legend('show',{'4 ohms','3 ohms','2 ohms','1 ohms','0.5 ohms'})