Solve an equation that has data arrays as constants

Illustration
Diego Torres-Siclait - 2021-12-08T15:00:52+00:00
Question: Solve an equation that has data arrays as constants

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!!!  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

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)

 


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!