Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

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

조회 수: 1 (최근 30일)
Jürgen
Jürgen 2012년 8월 22일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

Babak
Babak 2012년 8월 22일
Use
Z = trapz(X,Y)
  댓글 수: 3
Babak
Babak 2012년 8월 23일
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 2012년 8월 23일
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.

Community Treasure Hunt

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

Start Hunting!

Translated by