Integration of a function.

I'm trying to integrate a function but is giving be this error below
Incorrect dimensions for matrix multiplication.
Check that the number of columns in the first matrix matches the number
of rows in the second matrix. To perform elementwise multiplication, use '.*'.
I cant identify to set the dimention right but is still giving error. Please help me.
L=1;
T=100;
r=0.03;
I1=0.1;
p=0.1;
epsilon=0.3;
rho=1000;
beta= 0.1;
Cr=3000;
RhoP=0;
Mycp = 0:10:100;
n = zeros(numel(Mycp),1 );
n2 = zeros(numel(Mycp),1 );
n3 = zeros(numel(Mycp),1 );
Jcp = zeros(numel(Mycp),1 );
for i = 1:numel(Mycp )
MycpCurrent=Mycp(i);
delta = 1-MycpCurrent/100;
tau = (1/(beta*(L+delta*p)))*log((L*(I1+delta*p))/(delta*p*(L-I1 )));
t05 =(1/(beta*(L+delta*p)))*log((L*(0.05*L+delta*p))/(delta*p*(L-0.05*L )));
I2= @(t)(L*delta*p*(exp (beta*(L+delta*p)*t)-1)) ./ (L + delta*p* exp(beta*(L+delta*p)*t ));
I3= @(t)(L*(I1+delta*p)*exp((epsilon*beta)*(L+delta*p)*(t-tau))-...
delta*p*(L -I1))./(L-I1+(I1+delta*p)*exp(epsilon*beta*(L+delta*p)*(t-tau)));
fun = @(t,MycpCurrent) MycpCurrent*L*exp(-r*t);
fun2=@(t) rho*I2(t)*I3(t).*exp(-r*t)+((Cr*L*exp(-r*tau)));
fun3=@(t)RhoP*I2(t)*I3(t).*exp(-r*t);
n(i) = integral(@(t)fun(t,MycpCurrent),0,100, 'ArrayValued',1);
n2(i)= integral(fun2,t05,tau); %this is giving me error.
n3(i)= integral(fun3,tau,100);
end

 Risposta accettata

infinity
infinity il 16 Ago 2019

1 voto

Hello,
You just need to remove "." in the formulation of I2, I3, fun2 and fun3. The code will run withour errors.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by