MATLAB Answers

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

5 views (last 30 days)
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'

  0 Comments

Sign in to comment.

Accepted Answer

Gaurav Garg
Gaurav Garg on 1 Jun 2020
Edited: Gaurav Garg on 1 Jun 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 Comment

James Trinklein
James Trinklein on 4 Jun 2020
Thank you very much! I realized that I was having issues with domain and codomain of the function. Your help was much appreciated!

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Translated by