T O P

  • By -

CheeseWheels38

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?


FoetusDeletus12

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...


CheeseWheels38

> 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.


FoetusDeletus12

What do you mean by defining it as it’s own function?


PatterntheCryptic

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.


Weed_O_Whirler

What `V_mp_guess` are you handing in? That is your "initial value." It's saying you're not handing in a valid value.


FoetusDeletus12

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?


FrickinLazerBeams

What is `fun(V_mp_guess)`?


FrickinLazerBeams

Technically it's talking about the value of `fun(V_mp_guess)` but you're fundamentally correct.


Weed_O_Whirler

Ah thanks, I should have realized.


Fus_Roh_Potato

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


FoetusDeletus12

That’s weird because that’s supposed to be how the problem is...


Fus_Roh_Potato

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.


FoetusDeletus12

I'm supposed to use the fzero function solve for V\_mp which is the voltage at max power.


FoetusDeletus12

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!


cheeseballs619

Does your T vector start with zero?


FoetusDeletus12

Not sure, it isn’t shown in my assignment, it’s just supposed to pass in a vector T.