Clear Filters
Clear Filters

Is it possible to have a for-loop return multiple column vectors?

2 views (last 30 days)
The last for loop for p=1:length(a), Im trying to get multiple column vectors as the answer for b, 100 column vectors to be exact. I keep getting the error number of elements in A and B must be the same. Not sure if it is possible to get 100 column vectors as the answer, but if you can how do I fix the for-loop. Trying to solve a system of equations multiple times with different inputs, Here is my code.
a = linspace(1,24,1e2);
b = linspace(1,30,1e2);
x = linspace(0,2,1e3);
L = 2;
W1 = @(x) a + b*sqrt(sinh(x.^2));
y = zeros(length(a),1);
for k = 1:length(a)
W1 = @(x) a(k) + b(k)*sqrt(sinh(x.^2));
F(k) = integral(@(x) W1(x),0,L);
end
for i = 1:length(a)
W1 = @(x) a(i) + b(i)*sqrt(sinh(x.^2));
d1(i) = integral(@(x) x.*W1(x),0,L);
end
for j = 1:length(a)
d(j) = d1(j)/F(j);
end
A = [1 1
0 L];
for p = 1:length(a)
b(p) = [F(p); F(p)*d(p)];
end

Answers (1)

Walter Roberson
Walter Roberson on 3 Aug 2016
No.
You should be looking at cell arrays.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!