Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

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

1 view (last 30 days)
Jürgen
Jürgen on 22 Aug 2012
Closed: MATLAB Answer Bot on 20 Aug 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

Answers (1)

Babak
Babak on 22 Aug 2012
Use
Z = trapz(X,Y)
  3 Comments
Babak
Babak on 23 Aug 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 on 23 Aug 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.

This question is closed.

Community Treasure Hunt

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

Start Hunting!