What is wrong with my MATLAB code? Can someone check it for me..? (Sum of series)

2 vues (au cours des 30 derniers jours)
I have a problem with MATLAB coding. I'm trying to find the solution for the fractional-order equation. I already found for c0 until c3. Then I want to find sum of series as follow, and m=0,1,...,4. But I got error that said 'Index exceeds matrix dimensions'. Why this happened? And how to fix my code? I hope someone can help me.
clear;
syms x t D n h q
% Parameters needed to solve the equation
p = 0.012; % Proliferation rate (per day)
x0 = 25; % The middle of considered interval (mm)
epsilon = 0.01; % suggest by Ozugurlu
cmax = 62.5; % Carrying capacity of GBM tumour cells
alpha = 1.0; % Fractional derivative order
s = 0;
r = 1;
for m=2:3
c(1) = (1/((sqrt(2*pi()))*epsilon))*exp((-1/2)*(((x-x0)/epsilon)^2)); % Initial concentration (c0)
c(2) = (D/((sqrt(2*pi()))*(epsilon^3))-(D*((x0-x)^2))/((sqrt(2*pi()))*(epsilon^5))-p/((sqrt(2*pi()))*epsilon))*(h*((t^alpha)/(gamma(alpha+1))))*exp((-1/2)*(((x-x0)/epsilon)^2))+((h*p*(t^alpha))/(cmax*2*pi()*(epsilon^2)*(gamma(alpha+1))))*exp((((x-x0)/epsilon)^2)); % c1
d = diff(c(m),x,2);
c(m+1) = (n+h)*c(m)-(h*(t^alpha)/(gamma(alpha+1)))*(D*d+p*c(m)-(p/cmax)*((c(m))^2))
while r<=m
c = c(r)*(q^(r-1))+s;
s = c;
r = r+1;
end
end
disp('sum of series=')
disp(s)

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Avr 2020
inside the while loop you calculate something making use of c indexed at a value. you then store that on top of all of c, making c a scalar. Next time through the loop you try to index c but c is a scalar now.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by