MATLAB: How to declare function function I'm trying to understand declaration of functions in Matlab. I want to compute y(x)=x(sqrt(x)-sqrt(x-1)) for x= 10; 100; 1000; And after declaring it as a function(.m) how can I call this function? Thanks in advance Best Answer Dear Mustafa,function y = calculate_sqrt(x)y = x .* (sqrt(x) - sqrt(x - 1));endyou can save it with the name "calculate_sqrt.m"and then later you call it asx = [10 100 1000];y = calculate_sqrt(x);I hope it helps. Good luck! Related SolutionsMATLAB: How to declare Do you have the symbolic toolbox? If yes thansyms R Gr = 4/pi * atan((R-G)/(R+G));else you're more than likely going to hve to define R and G in terms of domains. For exampleR = 0:0.01:1;G = 0:0.1:10; %Make sure the matrix dimensions agree. r = 4/pi * atan((R-G)/(R+G));Matrix manipulation is what matlab was designed to do at its basic level. the symbolic stuff is an add on that works pretty well. MATLAB: Doubt in declaring a function No, there is not. You cannot name an element of a matrix in a function header. You can use two different variables though.function err = ODE_fit(fun, exp_t, exp_y, Q, theta1, theta2, iniVal)% exp_y = Experimental observation at time exp_t[t,y] = ode45(@(t,X)fun(t,X,n, S0, Q, theta1,theta2),exp_t,iniVal); err = sum(sum((y-exp_y).^2)); % compute error between experimental y and fitted yend Related Question
Best Answer