Non-linear equation MATLAB - matlab

I have no idea how I could solve this equation with matlab:
f(1)=0.098253*x(1)-atan((tan(x(1))-tan(x(2)))/2)*0.531268-0.433015*x(2)-0.27994
f(2)=0.9951*x(1)-atan((tan(x(1))-tan(x(2)))/2)*0.12909+0.866022*x(2)-0.350005;
I tryed with function = f and then [x,eval,flag]=fsolve('ecuaciones',x0); but I have an error:
Error in ==> fsolve at 254
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE
cannot continue.
And Matlab says to me that is double type... but I have no idea how I can resolve!! I am new using Matlab, for that reason I need the answer clearly!!
THANK YOU!

I dont think your equations can be solved for anything you've only one degree of freedom because f(2) is a multiple of f(1)

Related

solving nonlinear equations including max function

I want to solve this system of equations using MATLAB:
I solved the second equation and put it in the first one. Then I tried this:
syms v_star
eqn = max((1.8+0.81*v_star), (-1+0.9*v_star)) == v_star;
solx = solve(eqn,v_star)
And I get this error:
Error using symengine
Input arguments must be convertible to floating-point numbers.
How can I solve this system of equations?

Using Matlab to solve a system of ODEs using Euler's method

I have created a function Euler.m to solve a a system of ODEs using Euler's method. I wish to use this function to solve the system of ODEs defined by the anonymous function func=#(t) ([x(t)+4*y(t)-exp(t);x(t)+y(t)+2*exp(t)]) with initial conditions given by y0.
func=#(t) ([x(t)+4*y(t)-exp(t);x(t)+y(t)+2*exp(t)]);
y0=[4;5/4];
y_exact=#(t) [4*exp(3*t)+2*exp(-t)-2*exp(t);2*exp(3*t)-exp(-t)+exp(t)/4]; %exact solution of ODEs
a=0; % such that
b=1; % a<t<b
N=120;
[t,y] = Euler(func,a,b,y0,N)
However, the following error is displayed:
"Error using solution>#(t)([x(t)+4*y(t)-exp(t);x(t)+y(t)+2*exp(t)])
Too many input arguments.
Error in solution (line 7)
[t,y] = Euler(func,a,b,y0,N)".
Why is this error being displayed?
You are pretending that you already know when writing the ODE function func what the solutions x(t),y(t) are. Then you are going to compute solutions approximations for it. This is completely the wrong way around.
The function for the right side is just for a point in phase space, so you need
func=#(t,y) ([y(1)+4*y(2)-exp(t);y(1)+y(2)+2*exp(t)]);
where the input y is a two-component vector.

solving a quadratic equation with matrices in matlab

I'm trying to numerically find the solution to X^2+X+C=0 where C is the matrix C=[-6,-5;0,-6] and 0=[0,0;0,0], a quadratic equation where the variable is 2x2 matrix.
So I wrote the following matlab commands
C=[-6,-5;0,-6]
[X1,F,e_flag]=fsolve('X^2+X+C',[1,1;1,1])
where [1,1;1,1] is our initial estimate, or X0.
I'm getting the following errors
"Error using inlineeval (line 15)
Error in inline expression ==> X^2+X+C
Undefined function or variable 'X'.
Error in inline/feval (line 34)
INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr,
INLINE_OBJ_.expr);
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE
cannot continue."
How do I use fsolve to solve these kind of problems?
I don't think fsolve can be used with a string representation of your equation.
You should rather pass a function handle to the solver like this:
C = [-6,-5;0,-6];
[X1,F,e_flag] = fsolve(#(X) X^2+X+C,[1,1;1,1]);
It also depends on what you mean by: X^2. In Matlab this means the matrix product X*X. If you want entry-wise squaring you should use X.^2, in which case you will have four independent quadratic equations, which you could solve independently.

Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue

I am trying to solve a large set of non-linear equation using fsolve in MATLAB 2013. When I run this code:
Unkn0=zeros(3249,1); % Guess
[Unkn,feval,exitflag,output]=fsolve(Eqnh,Unkn0);
Here Eqnh is a function handle for 3249 variables and 3249 equations.
I get the following error:
Error using
Not enough input arguments.
Error in fsolve (line 218)
fuser = feval(funfcn{3},x,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FSOLVE cannot continue.
I can provide Eqnh written in a text file if there is any need of it.

Matlab fitting data to a function, where the function is a summation and periodic, syntax

I am attempting to fit temperature data over the last 50 years for the US using the lsqcurvefit, but I am concerned that my fitting function has bad syntax.
The fitting function itself is of the form:
∑(ai+bi*t+ci*t^2)*(cos(vt+p))
Summing from i=1 to N. I would like t to correspond to the time vector called TIME. Ideally the fitting should return values for a, b, c, v, and p which describe the temperature data
I am attempting to fit daily maximum temperatures, a vector called TMAX.
So far I have:
lsqcurvefit(fitFn(1,2,TIME),5,TIME,TMAX)
Where fitFn is defined in a script as
function f = fitFn(i,N,t)
f=0;
for i=1:N
f =#(i,N,a,b,c,v,p,t) f + (a+b*t+c*t^2)*(cos(v*t+p));
end
However whenever I run lsqcurvefit I get the error
Error using
fitFn>#(i,N,a,b,c,v,p,t)f+(a+b*t+c*t^2)*(cos(v*t+p)) (line
4)
Not enough input arguments.
Error in lsqcurvefit (line 199)
initVals.F =
feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial user-supplied objective function
evaluation. LSQCURVEFIT cannot continue.
I am sure I'm making a simple error but I'm somewhat at a loss. I'm new to MatLab and don't quite understand how to use anonymous functions. Any help would be greatly appreciated.
Thanks for reading
Your fitFn is very wrong. I think this is what you want:
f = #(x,t) (x(1)+x(2)*t+x(3)*t.^2)*cos(x(4)*t+x(5))
lsqcurvefit(f,zeros(1,5),TIME,TMAX)