Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

trying to parametrize code for 'solve' and 'syms' command

1 vue (au cours des 30 derniers jours)
Jürgen
Jürgen le 22 Août 2012
Clôturé : MATLAB Answer Bot le 20 Août 2021
Hi,
Below I show code for using syms and solve with order 3, but I want to automatically generate also other orders.(like up to 13) I think I can make the stringe for the 'int' function automatically but I don't know how to make the comma separated input for solve, If I add the comma in the input string it is interpreted as part of the string, not as a separator between different equations.
syms x a1 a2 a3 % integrate for Counter=1:NbOfCoef Eq{Counter}=int('a1*x^2+a2*x^3+a3',StartPoint(Counter),EndpPoint(Counter)); end % Solve system Amountstr = num2str(Amount*-1); % Create Equations for Counter=1:NbOfPositions EqNew{Counter}=[char(Eq{Counter}) Amountstr(Counter,:)]; end % Solve the system S=solve(EqNew{1},EqNew{2},EqNew{3});
thanks for all possible input,
regards,
Jürgen

Réponses (1)

Babak
Babak le 22 Août 2012
Use
Z = trapz(X,Y)
  3 commentaires
Babak
Babak le 23 Août 2012
Your question is not clear enough to understan at least to me.
As far as I know you can do numerical integration with trapz() function. If you have a function and you want to integrate it, you can create a vector of input X and output Y for that function (like Y=func(X)) and then use trapz(X,Y). This is omplete numerical.
Now if you want to integrate your function and find a new funtion (not the value of the integral) you must use MATLAB Symbolic Math Toolbox, or write your own routines to do the integration. I suppose you want to write your own routines to integrate a function and find the integrated function. This is not easy and you may not be able to do it for any random function, while it is easy for some specific kinds of functions like polynomials. As far as I can see in your equations you may want to integrate a polynomial. I am not sure though. But it is pretty easy to do that. Just use the general rule that integral (over x domain) of a*x^n equals to a/n * x^(n+1).
I hope that helps.
Jürgen
Jürgen le 23 Août 2012
Hi, as you can see I have edited my question: I have indeed used the symbolic toolbox and then it is quite easy to do the integration.But I want to parametrize the code that implements the symbolic integration and the solver so I can test for different grades of the polynomial.

Cette question est clôturée.

Community Treasure Hunt

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

Start Hunting!

Translated by