14 November 2019 3 5K Report

I am trying to solve a system of non-linear equations, I have successfully coded it using MATLAB making use of the symbolic toolbox but my code has to be C/C++ compatible. I am therefore seeking guidance on how I go about solving a nonlinear equation/equations using a "while loop"? For example, this function calculates a for me by numerically solving F for a given z: function [a] = F3 (z) syms theta theta_o = -0.058*log(1/z)+0.3366 ; Vo = 2*log(theta_o/(1-theta_o))+2*(theta_o/(1-theta_o))-27/2*z*theta_o ; F = (2*log(theta/(1-theta))+2*(theta/(1-theta))-27/2*z*theta)-Vo ; a = vpasolve(F , theta , 0.1) ; end and this one calculates ap for me by numerically solving the derivative of F for a given z: function [ap] = F4 (z) syms theta theta_o = -0.058*log(1/z)+0.3366 ; Vo = 2*log(theta_o/(1-theta_o))+2*(theta_o/(1-theta_o))-27/2*z*theta_o ; F = (2*log(theta/(1-theta))+2*(theta/(1-theta))-27/2*z*theta)-Vo ; dF = diff(F); ap = vpasolve(dF , theta , [0 theta_o-0.00001]) ; end How do I solve this iteratively using a "while loop"?

Similar questions and discussions