필터 지우기
필터 지우기

Finding the definite integral of a constant?

조회 수: 2 (최근 30일)
Rachel
Rachel 2013년 1월 16일
Hello. I'm writing a program for class which solves Gauss's Law numerically and plots points. The problem I'm running into is in the integral. Gauss's Law for a sphere can be rearranged into two definite integrals: the integral of sin(theta) from 0 to pi and the integral of 1 from 0 to 2pi. I used trapz for both:
theta = 0:pi/100:pi;
polarintegral = sin(theta);
phi = 0:pi/100:2*pi;
azimuthintegral = 1;
polar = trapz(theta, polarintegral);
azimuth = trapz(phi, azimuthintegral);
The theta integral works perfectly. Matlab, however, doesn't seem to understand how to integrate 1, since it's not a function of phi. The project instructions says that we're not allowed to solve the integral for the program, even if it's simple. Does anybody have any ideas how I might be able to fix this snag?
By the way, I'm using Matlab 2009b in case that makes a difference. Thank you!

채택된 답변

Shashank Prasanna
Shashank Prasanna 2013년 1월 16일
편집: Shashank Prasanna 2013년 1월 16일
Maybe you want to do this instead:
az = ones(length(phi),1);
azimuth = trapz(phi, az)
  댓글 수: 1
Rachel
Rachel 2013년 1월 16일
Thank you so much! It worked perfectly and now my program runs like it should! Now to adapt it for the more complex problems.

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by