MATLAB Answers

fsolve for a set of equations

1 view (last 30 days)
Ann
Ann on 8 Apr 2020
Commented: Torsten on 8 Apr 2020
Hi,
I have a trouble solving this set of equations:
syms E
f1 = (-j*(sqrt(((2*mb)./h_.^2)*(E - V0) - k_I(i).^2))/mb) - ((sqrt(((2*mw./h_.^2)*E) - k_I(i).^2))/mw)*tan(0.5*(sqrt(((2*mw./h_.^2)*E) - k_I(i).^2))*a);
f2 = (-j*(sqrt(((2*mb)./h_.^2)*(E - V0) - k_I(i).^2))/mb) + ((sqrt(((2*mw./h_.^2)*E) - k_I(i).^2))/mw)*cot(0.5*(sqrt(((2*mw./h_.^2)*E) - k_I(i).^2))*a);
F = @(E) [f1; f2];
x0 = [10;10];
[F, fval] = fsolve(F, x0)
I get an error 'FSOLVE requires all values returned by functions to be of data type double.'. How can I correct the code? And what's the best way to solve such set of equations?
Thank you for any help provided to that issue.
Kind regards,
Ann

  0 Comments

Sign in to comment.

Answers (1)

darova
darova on 8 Apr 2020
Try this
syms x
a = 1;
b = 2;
f = a*x+b;
F = matlabFunction(f);
fsolve(F,1)

  1 Comment

Torsten
Torsten on 8 Apr 2020
Or just remove the line
syms E

Sign in to comment.

Sign in to answer this question.


Translated by