anonymous
  • anonymous
Matlab: I have written about 40 programs so far for this one class. I have come across a problem I'm having troubles seeing through clearly or even how to write it. It is using a function to compute the derivative (not the derivative function that may already be in the matlab library, but a fully written out one)
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
the equation is\[f \prime(x _{i}) =[ f(x _{i+1}) - f(x _{i})]/ \Delta x\] where \[\Delta x = x _{i+1} - x _{i}\]
anonymous
  • anonymous
here is a start my teach provided %defining the function for problem 5.24 function dy = deriv1(xmin, xmax, step, f) %last param f is function %write a loop to go through the values of x %and calculate dydx(i) = ... f(x(i) + step) - f(x(i))... % calling function f end
shadowfiend
  • shadowfiend
When does it end? Which is to say, do you have a definition for \(x_i\) for some value of i?

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
I don't understand your problem, do you have Calc I experience? The function is rather straight forward.
anonymous
  • anonymous
yeah i have calc i and ii so far. I am learning matlab so this seems very complicated to write in matlab though i havent tried the problem yet. it seems like a fun one and thought i would throw it out there. right now im working on writing a function that calculates the mins and maxes of a function on a range of x values. so i havent had time to try to solve this one
anonymous
  • anonymous
Well, the function can be found on wikipedia, ie f'(a) = lim (f(a+h) - f(a)) / h So just figure out f'(a) for each point from xmin to xmax stepping by step. Is your problem finding f'(a)? Or is the problem with the stepping?
anonymous
  • anonymous
I haven't really looked at this one yet. I have been stuck on this one program for the last 3 classes. I thought I would be able to start this one a lot sooner. So I think this derivative problem will be easier after I figure out this problem. Maybe you could look at it? Its to find the min and max values of any arbitrary function. it has four inputs and four out puts. but I keep getting an error "??? Undefined function or variable 'x'." my program is this and it is wrong because of the error. I know something essential has to be missing. I am stuck on how to take an arbitrary function and use it in my function.
anonymous
  • anonymous
%inline function must be used in place of func. The inline function %requires a string input. function [xmin, min_value, xmax, max_value] = minmax(first_value, last_value, num_steps, func) step_size = (last_value - first_value)/num_steps x = first_value:step_size:last_value [i_min min_value] = min(func(x)) [i_max max_value] = max(func(x)) xmin = x(i_min); xmax = x(i_max); end
anonymous
  • anonymous
I'll take a look at it in a few hours. I'm at school at the moment waiting for a couple of students to turn in assignments so that I can finish the grading up for the semester. I'll fire up matlab when I get home, I'm fairly rusty atm.
anonymous
  • anonymous
Good luck lando! I do know now that this code does work, i got this far. % to call function: [a b c d] = minmaxa(1,2,3, @func) %function [xmin, min_value, xmax, max_value] = %minmaxa(first_value, last_value, num_steps, f) step_size = (last_value - first_value)/(num_steps-1); x = first_value:step_size:last_value; y = f(x); [cmin index] = min(y) min_value = cmin xmin = x(index) [cmax index] = max(y) max_value = cmax xmax = x(index) end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% But i could only get it to work for sin. I do note in the top to call the function you can write exactly that but instead of func, you use something in terms of x like: x.^2 + 2*x The @ is the "function handle" and has to be used. give it a try with the sin func. copy and paste this for the round brackets (0,2pi,100,@sin) kinda cool. the min should be -1 max should be 1. My problem is getting some other function like the x.^2 + 2*x I was going to try to write a separate file to do it.

Looking for something else?

Not the answer you are looking for? Search for more explanations.