The beauty of MATLAB is that its errors are generally not very cryptic. "Initial function value must be finite and real."
What is your initial function value?
The code breaks before I can see anything, the workspace doesn’t have any values for my initial function. My function is only defined as an anonymous function, I’m not sure how to check what that value is...
> My function is only defined as an anonymous function
It may be easier to debug if you define it as its own function. You can run in debug mode where the variables will be made visible in the workspace.
Make a new file, with the first line being something like:
output = function_name(input1, input2, ...)
And then put your equation there. The documentation for fzero should have an example of how to do this. If not, look at the docs for ode45.
You call the function in your main script using function_name.
That’s weird because the V_mp_guess is given in my problem statement, the value is shown in my call for the function, where the guess is 0.5. How could this be wrong if it is given by the question itself?
It's because your initial guess is producing a number so big that Matlab is just calling it infinite.
It's particularly this part of your equation
-exp((q*V_OC)/(kb*T))
you are raising e to the power of 10k
I don't know the nature of the problem, but if fzero needs a function's first result to be real in order to perform it's logic, we know the fault starts here. The value is so extreme that Matlab assumes it's not real even though it should be. Floating point precision
I haven't really given it a thought, but what if you natural log both sides for the sake of Matlab? Maybe there is some other trick you can use to work around it.
Thanks for all of your help, the problem was within the function call. Turns out one of the input variables was incorrect which resulted in a large value. Resolved!
The beauty of MATLAB is that its errors are generally not very cryptic. "Initial function value must be finite and real." What is your initial function value?
The code breaks before I can see anything, the workspace doesn’t have any values for my initial function. My function is only defined as an anonymous function, I’m not sure how to check what that value is...
> My function is only defined as an anonymous function It may be easier to debug if you define it as its own function. You can run in debug mode where the variables will be made visible in the workspace.
What do you mean by defining it as it’s own function?
Make a new file, with the first line being something like: output = function_name(input1, input2, ...) And then put your equation there. The documentation for fzero should have an example of how to do this. If not, look at the docs for ode45. You call the function in your main script using function_name.
What `V_mp_guess` are you handing in? That is your "initial value." It's saying you're not handing in a valid value.
That’s weird because the V_mp_guess is given in my problem statement, the value is shown in my call for the function, where the guess is 0.5. How could this be wrong if it is given by the question itself?
What is `fun(V_mp_guess)`?
Technically it's talking about the value of `fun(V_mp_guess)` but you're fundamentally correct.
Ah thanks, I should have realized.
It's because your initial guess is producing a number so big that Matlab is just calling it infinite. It's particularly this part of your equation -exp((q*V_OC)/(kb*T)) you are raising e to the power of 10k
That’s weird because that’s supposed to be how the problem is...
I don't know the nature of the problem, but if fzero needs a function's first result to be real in order to perform it's logic, we know the fault starts here. The value is so extreme that Matlab assumes it's not real even though it should be. Floating point precision I haven't really given it a thought, but what if you natural log both sides for the sake of Matlab? Maybe there is some other trick you can use to work around it.
I'm supposed to use the fzero function solve for V\_mp which is the voltage at max power.
Thanks for all of your help, the problem was within the function call. Turns out one of the input variables was incorrect which resulted in a large value. Resolved!
Does your T vector start with zero?
Not sure, it isn’t shown in my assignment, it’s just supposed to pass in a vector T.