xyz
xyz

Reputation: 407

How to use fsolve() with det()

I want to solve det(A)=0 for a large matrix A with each element a function of w.

One way to solve these (simple) problems is using a symbolic approach, e.g.:

A = sym('[w, 1; 2, 4*w^2 + 2]');
answer = solve(det(A),'w');

However, I want solve a much larger problem where the equation of each element is defined as a function handle (e.g. A4 = @(w) 4*w^2 + 2;), and may need to be solved numerically with fsolve().

The problem is that I cannot directly put the function handles in matrix A - they need to be put in a cell array, but then solve(det(A)) is incompatible with cell arrays and returns "Undefined function 'det' for input arguments of type 'cell'."

How do I solve the problem?

Upvotes: 0

Views: 137

Answers (1)

Nemesis
Nemesis

Reputation: 2334

I have tried to following approach using you minimal example.

% Defining all functions as cells:
f{1,1} = @(w)w;
f{1,2} = @(w)1;
f{2,1} = @(w)2;
f{2,2} = @(w)4*w.^2+2;

% Function to solve
fsol = @(w)det(cellfun(@(x)x(w),f));

% Using fsolve
fsolve(fsol,0)

The result is

0.5898

which is equal to the (real) solution using symbolic math.

Upvotes: 2

Related Questions