Unable to perform assignment because the indices on the left side are not compatible with the size of the right side. (using vpasolve)

1 次查看(过去 30 天)
Hi, I'm trying to run the following code to find the a coefficient for several catenaries as part of a lab class. It keeps giving me the above error and I'm not sure what's going on. When I run the code using answer(i,:) instead of answer(i) it puts out a 5x0 array. What's going on?
clear all
close all
clc
x = [
-41.0
-35.0
-34.0
-33.0
-33.0
];
y = 38;
syms a;
for i = 1:length(x)
answer(i) = vpasolve((a.*cosh(x(i)./a)==38,a);
end
b = answer'
x = [49.1
55.1
56.1
57.1
57.1];
y = [38.5
57.6
60.1
61.3
63.3];
for i = 1:length(x)
answer2(i) = vpasolve(a.*cosh(x(i)./a)== y(i),a);
end
c = answer2'

采纳的回答

Gaurav Garg
Gaurav Garg 2020-6-1
编辑:Gaurav Garg 2020-6-1
Hey James
Assuming that the equations written by you are correct, and ( (parenthesis) placed by you are fine too, the vpasolve function returns an empty sym: 0-by-1. You can check it by executing:
vpasolve(a.*cosh(x(i)./a)==38,a);
This means that vpasolve cannot find a solution and would then return an empty object.
So, each time you run the iteration over i, vpasolve would return a 0 x 1 array; and answer array would finally get the size 5-by-0. This is also the reason you get the error 'Unable to perform assignment because the left and right sides have a different number of elements'.
To get rid of the error, you might have to check the correctness of the equations written by you, or you can provide an initial guess to help the solver find a solution - link.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Number Theory 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by