Unable to perform assignment because the left and right sides have a different number of elements. Error in y_vector(k) = Fk + r* e1* y_vector(1)+ r* (B

clear all
format short
alf = 0.5;
bet = 1;
a = 0;
b = 1;
fi = 6;
r = alf / (1 - alf);
n = 10;
h = (b - a) / n;
t_vector = zeros(1, n);
y_vector = zeros(1, n);
% Calculate e3 and ealf
e3 = mlf(alf,bet,-r*(t_vector.^alf),fi)
Unrecognized function or variable 'mlf'.
ealf = mlf(alf,alf,-r*(h^alf),fi)
B1 = (h^alf) / gamma(alf + 2)
B2 = ((h^alf) * ealf) / (alf + 1)
y_vector(1) = 0;
for k = 2:n
summation= 0;
for j = 2:k
summation = summation + (B1 * y_vector(j) - B2 * y_vector(j-1))
end
e1 = mlf(alf,1,-r*(t_vector(k) - t_vector(1)),fi)
Fk = ((1 / (1 - alf)) * (gamma(3) * (t_vector(k)^2) * e3)) + t_vector(k)^2
y_vector(k) = Fk + r* e1* y_vector(1)+ r* (B2 * y_vector(k-1)) + r* summation;
end
y_vector

1 commentaire

There is an undefined parameter in your code, see above, thus we can not run your code to reproduce the error.

Connectez-vous pour commenter.

Réponses (1)

hello
seem to me there is an issue with y_vector update as you add Fk (array size 1x10) with the rest (+ r* e1* y_vector(1)+ r* (B2 * y_vector(k-1)) + r* summation) which is a scalar , and you assign that to a output scalar y_vector(k)
maybe you needed to index Fk , so this line should be written :
y_vector(k) = Fk(k) + r* e1* y_vector(1)+ r* (B2 * y_vector(k-1)) + r* summation;

4 commentaires

y_vector and fk are giving zeros. what can i do to fix that
t_vector is an array initialized with zeros so Fk is always an array of zeros
Fk = ((1 / (1 - alf)) * (gamma(3) * (t_vector(k)^2) * e3)) + t_vector(k)^2
summation is another variable that is always zero
from there y_vector(k) is always zero as all terms on the RHS of the equation are always zero(s)
y_vector(k) = Fk(k) + r* e1* y_vector(1)+ r* (B2 * y_vector(k-1)) + r* summation;
somewhere either there is a mistake in the initialization or the equations are wrong or updated not in the correct way
"t_vector is an array initialized with zeros so Fk is always an array of zeros"
Fk is a scalar 0, because it has the kth element of t_vector, not the whole array itself.
@Noor - We do not know what your objective is, there are no comments in your code to refer to, nor do we have all the code.
You will have to provide more information as to what you are trying to do and the full code if you need help from us.

Connectez-vous pour commenter.

Tags

Question posée :

le 23 Oct 2023

Commenté :

le 23 Oct 2023

Community Treasure Hunt

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

Start Hunting!

Translated by