# Solve an equation that has data arrays as constants

1 view (last 30 days)
Diego Torres-Siclait on 2 Dec 2021
Hello,
I want to solve the following equation:
1/c0 c^2 - c +X*t / c0 = 0
where c0 is a given constant but X and t are constant arrays: they are data sets where X varies with time, t. The goal is to solve for c, which too will be a data array that varies with time, t.
I tried:
func = @(c) 1/c0.*c^2 - c + X.*t/c0;
c = fzero(func,1)
But got errors likely because X and t are arrays and not single values. Any other ideas? Time sensitive, thank you!!!

Walter Roberson on 2 Dec 2021
You have c^2 and say that c will be an array.
Could you confirm that you c^2 meaning c*c meaning algebraic matrix multiplication (inner product) of c with itself?
If you do then all of the values have to be searched for simultaneously, which makes it a multivariate problem, but fzero() can only be used for univariate situations. fsolve() can be used for multivariate cases.
Also is X*t intended to be algebraic matrix multiplication like in your problem definition, or is it X.*t like in your code?
XTc0 = X.*t./c0;
c = arrayfun(@(xtc0) fsolve(@(c) 1/c0.*c.^2 - c + xtc0), XTc0)
Diego Torres-Siclait on 3 Dec 2021
great, thank you Walter!

### Community Treasure Hunt

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

Start Hunting!