Here are my codes, I keep getting wrong feedback which drive me crazy! Here's the problem: Basicly the problem is to solve a nonlinear equation by using the fzero command. The function is Φ(r)=[Φ0*e^-r/delta]/(4*pi*D*r) And solve r when Φ(r)/Φ0=10% Every parameters are in the command
My problem is: Index exceeds matrix dimensions.
Error in YZHW61 (line 47) fprintf(' %6.3f %2u %6.2f %+6.2E \n',...
%%YZHW61
%Find the distance away from the point source of laser
%
%Written 2/11/2012 by YZ
%Last updated 2/11/2012 by YZ
%
%First list parameters
%μs’=μs(1-g)=10cm-1
%μt’=μa+μs’=10.1cm-1
%D=(1/3)*μt’=3.37cm-1
%δ=sqrt(D/μa)=5.8
%So the final equation becomes Φ(r)=(Φ0*e^(-r/5.8))/(4*pi*3.37*r)
%Simplify the equation and we get:
%Φ=(e^(-r/5.8))/13.48*pi*r where Φ(Phi)=Φ(r)/Φ0 that represents the
%percentage of the new light intensity compared to the original
%light intensity
date
clear all
%First plot Diffusion Equation for r between 0.5 and 100
for i=1:1:200; %loop counters musht be be nonzero,positive integers
r=i/2; %this will give us 0.5cm distance
press(i)=r;
g=0.9;
mius=100;
miua=0.1;
mius1=mius*(1-g);
miut1=miua+mius1;
D=(1/3)*miut1;
delta=sqrt(D/miua);
P(i)=exp(-r/delta)/(4*pi*D*r)*100;
end
hold on
plot(press,P);axis equal; grid
%
% Get user input for the light fluence rate(percentage)
%We need to pass this information to the function by using the global
%variable
global Phi
Phi=0.1;
%
%Choose initial guess
distance=1;
[r,error,exitflag,output]=fzero(@Diffusion,distance);
%
%What's the solution, how many iterations, what's the error?
fprintf=('distance (Iterations fluence rate error) \n');
fprintf(' %6.3f %2u %6.2f %+6.2E \n',...
r, output.funcCount, Phi, error)
plot(r,0.1,'o')
And here is my function:
function Pest=Diffusion(distance)
%Diffusion equation for distance r
%
%First written by YZ on 2/11/2012
%Last updated by YZ on 2/11/2012
%
global Phi
g=0.9;
mius=100;
miua=0.1;
mius1=mius*(1-g);
miut1=miua+mius1;
D=(1/3)*miut1;
delta=sqrt(D/miua);
Pest=exp(-distance/delta)/(4*pi*D*distance)*100-Phi;
end
Really appreicate anyone who can help me!

2 个评论

What problem are you encountering? There is nothing in your source that an on-looker would clearly understand to be "feedback", and you have not mentioned any error message.
Yu
Yu 2012-2-12
I'm so sorry, please see the edited verision.

请先登录,再进行评论。

 采纳的回答

Image Analyst
Image Analyst 2012-2-12
Several errors in your code. The big one is this line:
fprintf=('distance (Iterations fluence rate error) \n');
You are not allowed to have an equal sign after fprintf(). I think what you did was to essentially overwrite fprintf with a character string. Then in the next line you tried to access some element of the string beyond the end of it.
Secondly, you are overwriting error(). DON'T DO THAT! It's a built in function. Use "errorStructure" as the name instead of "error".
[r,errorStructure,exitflag,output]=fzero(@Diffusion,distance);

9 个评论

Yu
Yu 2012-2-12
Thank you for your answer, however, I changed r from 0.005 to 1 and changed the initial guess to 0.005 due to my understand and graph to the function; but then I encountered a new problem: too many output arguments.It that because I choos the wrong initial guess? Because I changed to different values and still get the same mistake.
I don't care at all about those. Did you change what I said to change? Did you remove the equal sign and rename error to errorStructure?
Yu
Yu 2012-2-12
I did; actually the changes are made after I did what you want me to change.
I don't see how r was ever .005. I see that it was r=i/2. Where does it now equal 1? Also, what line said that some function had too many output arguments? It helps if you paste the error.
Yu
Yu 2012-2-12
Error using error
Too many output arguments.
Error in YZHW61 (line 47)
fprintf(' %6.3f %2u %6.2f %+6.2E \n',...
This is my error.
And I set r range from 0.005 to 1; because i have to be nonzero and positive figures so I let r=i/200 to get the range of r.
for i=1:1:200; %loop counters musht be be nonzero,positive integers
r=i/200; %this will give us 0.005 distance
Doesn't make sense. You're not using "error" anymore, remember? I told you to change it to "errorStructure" and you said you did.
Yu
Yu 2012-2-12
distance=0.005;
[r,errorStructure,exitflag,output]=fzero(@Diffusion,distance);
This is what I did according to your suggestion.
Yu
Yu 2012-2-12
Got it, thank you so much !
I guess you also eventually remembered to change it in the fprintf() also.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Programming 的更多信息

产品

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by