MATLAB: I need to solve an equation involving squares and cubes. MATLABsolving equations I need to sole this equation for L, and I have a set of values for d and p. p = -2(d/L)^3 + 3(d/L)^2 Im wondering how to put this into Matlab. Any help would be apprecitated. Best Answer It is a 3rd order equation, it has only an analytical solution. You can use the following code:clc; clearvars; syms p d L p=1; d=3; eq= p == -2*(d/L)^3 + 3*(d/L)^2 % analytical solution solve(eq,L) %numerical solution vpasolve(eq)And in case you want to run this for a set of values , you can do the following: clc; clearvars;syms p d L% values for p, dpValues=50:10:90;dValues=300:50:600;% an empty buffer for the solutions, combined with p,dSolBuffer=cell(length(pValues)*length(dValues),3);% solution counterk=0;for n=1:length(pValues) for m=1:length(dValues) k=k+1; p=pValues(n); SolBuffer{k,1}=p; d=dValues(m); SolBuffer{k,2}=d; eq= p == -2*(d/L)^3 + 3*(d/L)^2; % analytical solution solve(eq, L); %numerical solution SolBuffer{k,3}=vpasolve(eq).'; endend% An example: the third solutiondisp('data p and d :')disp(SolBuffer{3,1})disp(SolBuffer{3,2})disp('solutions:')disp(SolBuffer{3,3}) Related SolutionsMATLAB: How to plot this code correctly Read the documentation on histc() and in particular pay attention to the multiple-output version of it. MATLAB: How to plot this equation t = 0 : 0.1 : 1;for K = 1 : length(t) p(K) = (B-(b*t(K)))/(sigma); endplot(t, p)(Note: there are more efficient ways of doing it, but this is the closest correspondence to your current code.) Related QuestionHow get the maximal positive root of polynomialSolution of Non linear EquationHelp solve a system of Differential Equations
Best Answer