MATLAB: Writing and plotting function with multiple conditions functionMATLABmatlab functionplotplotting Imagine I have a function like this: How can I write this function in matlab and plot it between 0 and 1? How can I also compute of this function? I want to have something like f=@(x) my_func Best Answer One possibility:f = @(x) 9/5*x*(0<=x & x<1/2)+9/5*(1-x)*(1/2<=x & x<=1);e.g.f(0.1)ans = 0.1800>> f(0.75)ans = 0.4500 Related SolutionsMATLAB: Functions with different conditions >> f = @(x) x.^2.*(x>1) + x.^4.*(x<=1);>> integral(f,0,2)ans = 2.5333 MATLAB: How to put strings on the x axes neworder = { 'N2' [0.1700] 'HC' [0.1700] 'SAGD' [0.1800] 'Steamflood' [0.4500] 'CSS' [0.4500] 'hot Water' [0.4500] 'CO2' [0.5100] 'Polymer' [0.6300] 'ASP' [0.6300] 'Combustion' [0.6500]}bar([neworder{:,2}])set(gca,'XtickL',neworder(:,1)) Related QuestionHow to plot below function fHow to define an array within a loop. I am trying to calculate and store some variables provided some conditions are true.Can someone please tell me how to correctly define array x(i,j) for thisCreate a function and plot itHow i can sum only positive number in each row of matrixFsolve or fzero for this system of nonlinear equation
Best Answer