Something must be a floating point scalar?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Mathidiot Superfacial
il 14 Mar 2016
Commentato: Walter Roberson
il 10 Apr 2022
f=@(x,y) sqrt(9-x.^2-y.^2);
xmax=@(y) sqrt(9-y.^2);
volume=integral2(f,0,xmax,0,3)
But it says XMAX must be a floating point scalar? What's wrong?
0 Commenti
Risposta accettata
James Tursa
il 14 Mar 2016
Modificato: James Tursa
il 14 Mar 2016
The error message seems pretty clear. The x limits must by scalar values. The y limits can be functions of x. Just rearrange things so that is the case. Since f is symmetric with respect to x and y, you can just switch arguments.
integral2(f,0,3,0,xmax)
2 Commenti
Walter Roberson
il 14 Mar 2016
Modificato: Walter Roberson
il 14 Mar 2016
For 2D integrals, theory says that it does not matter which order you evaluate the integration. So define the function handle to be integrated so that the first parameter is the one with fixed bounds and the second parameter is the one with variable bounds. Remember it is not required that x be the first parameter.
f = @(y, x) x.^2 + x.*sin(y).^2;
xmax=@(y) sqrt(9-y.^2);
integral2(f, 0, 3, 0, xmax )
Più risposte (1)
Albert Justin
il 10 Apr 2022
Enter the function f(x,y)=@(x,y) x.*y
Enter the outer integral lower limit:0
Enter the outer integral upper limit:a
Enter the inner integral lower limit:@(x) x.^2
Enter the inner integral upper limit:@(x) 2-x
i get the same error
1 Commento
Walter Roberson
il 10 Apr 2022
a = 5;
f = @(x,y) x.*y
xmin = 0
xmax = a
ymin = @(x) x.^2
ymax = @(x) 2-x
integral2(f, xmin, xmax, ymin, ymax)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!