Matlab turns scalar parameter into array when numerically integrating

조회 수: 2 (최근 30일)
Fabian
Fabian 2013년 3월 19일
When I numerically integrate a function, for example:
function [ y ] = funci(x)
z = [1 ; 2 ; x];
A = diag(z);
...
end
by writing
integral(@(x)funci(x),0,2)
then the integration will turn x into an array with values from 0 to 2. This doesn't matter for simple integrations but in this case, it causes an error in the second line of the function (the one starting with "z="). Any solutions? I have been stuck on this for the last hours :/ cheers

답변 (1개)

Youssef  Khmou
Youssef Khmou 2013년 3월 20일
hi Fabian
I think the error( besied i do not own the "integral" function) is that your function returns a matrix , but integral takes an input as one dimensional function then if your function returns 2D data, you need to use other function such as double integral or dblquad,..or you have to map your function from 2D to 1D .
Take this as proposition , not definite answer .
cordially
  댓글 수: 1
Fabian
Fabian 2013년 3월 20일
Hi, thanks for your answer
The function actually returns a scalar. For example the determinant of A. Hence, this should not be the problem. Moreover, the error occurs in the second line already because Matlab can't fit the array (x) into the vertical array A, even though x should be a scalar.
Cheers

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by