fsolve Assignment has more non-singleton rhs dimensions than non-singleton subscripts

조회 수: 5 (최근 30일)
Hi, I have a symbolic integration and I need to use fsolve for my nonlinear 2 by 2 system:
function F=torder1(x)
% clear all; clc; close all;
x_1=[0:0.01:1];
b=0.6;
T = [0:0.01:1]; % this is time vector
clear x_1;
syms x_1 h theta kappa
f_11(x_1,h,theta) = 1-( (h+(x_1-b)*theta)^2/(h+(x_1-b)*theta-1*x_1*(1-x_1))^2 );
f_21(x_1,h,theta) = (x_1-b)/2*( 1-( (h+(1-b)*theta)^2/(h+(x_1-b)*theta-x_1*(1-x_1))^2 ));
fint_1 = int(f_11, x_1);
fint_2 = int(f_21, x_1);
x_1=1;
upper_1=subs(fint_1);
upper_2=subs(fint_2);
clear x_1;
x_1=0;
lower_1=subs(fint_1);
lower_2=subs(fint_2);
clear x_1;
integral_result_1old=upper_1-lower_1;
integral_result_2old=upper_2-lower_2;
h0 = kappa *b*(1-b);
theta0 = kappa*(1-2*b);
integral_result_1 = subs(integral_result_1old, {h, theta}, {x(1), x(2)})
integral_result_2 = subs(integral_result_2old, {h, theta}, {x(1), x(2)})
%
F = [x(1) - integral_result_1 -h0;
x(2) - integral_result_2 - theta0]
When I use this code, I have the error in the title.
Thanks for help.

채택된 답변

Walter Roberson
Walter Roberson 2016년 8월 20일
integral_result_1 and integral_result_2 are symbolic functions, not symbolic formula and not numeric values. They are functions of x_1, h, theta , but when numeric x are passed in, they are independent of x_1, h, and theta, but dependent on the undefined kappa. You cannot do a vertical concatenation of two functions, it appears. And if you could, then they would be the wrong data type (function) for an fsolve result. If you changed them so that they were symbolic expressions instead of symbolic functions then you would still have the undefined symbol kappa.
The function that you apply fsolve() to must return numeric values.
  댓글 수: 2
Meva
Meva 2016년 8월 20일
I have deleted my kappa by mistaken. It was kappa=1;
I do not understand your comment about "You cannot do a vertical concatenation of two functions, it appears." I had a look fsolve example in the MathWorks page and I wrote this code.
Now, question raises "How can I change symbolic expressions which were symbolic functions before"?
Anyway thanks for the help Walter.I will investigate the question I just asked.
Walter Roberson
Walter Roberson 2016년 8월 21일
Change
f_11(x_1,h,theta) = 1-( (h+(x_1-b)*theta)^2/(h+(x_1-b)*theta-1*x_1*(1-x_1))^2 );
f_21(x_1,h,theta) = (x_1-b)/2*( 1-( (h+(1-b)*theta)^2/(h+(x_1-b)*theta-x_1*(1-x_1))^2 ));
to
f_11 = 1-( (h+(x_1-b)*theta)^2/(h+(x_1-b)*theta-1*x_1*(1-x_1))^2 );
f_21 = (x_1-b)/2*( 1-( (h+(1-b)*theta)^2/(h+(x_1-b)*theta-x_1*(1-x_1))^2 ));
Change
F = [x(1) - integral_result_1 -h0;
x(2) - integral_result_2 - theta0];
to
F = [double(x(1) - integral_result_1 -h0);
double(x(2) - integral_result_2 - theta0)];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by