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

1 vue (au cours des 30 derniers jours)
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'

Réponse acceptée

Gaurav Garg
Gaurav Garg le 1 Juin 2020
Modifié(e) : Gaurav Garg le 1 Juin 2020
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.
  1 commentaire
James Trinklein
James Trinklein le 4 Juin 2020
Thank you very much! I realized that I was having issues with domain and codomain of the function. Your help was much appreciated!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by