Advertisement
kimo12

Untitled

May 17th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. function [func] = help(equation)
  2. y = char(equation);
  3. pattern = 'x';
  4. arr= strfind(y,pattern);
  5. n = 1;
  6. coffecinet = 1;
  7. coff = {''};
  8. while(n <= size(arr,2))
  9. position = arr(n);
  10. if(y(position+1) ~= '^' && y(position+1) ~= ')')
  11. if(y(position - 1) == '*')
  12. b = 2 ;
  13. while(y(position-b)~='+'||y(position-b)~='-')
  14. b=b+1;
  15. if(position-b==0)
  16. b=b-1;
  17. break;
  18. end
  19. end
  20. t=b-1;
  21. while(t>=2)
  22. coff = strcat(coff,y(position - t ));
  23. disp(coff);
  24. t=t-1;
  25. end
  26. coffecinet = str2double(coff);
  27. disp(coffecinet);
  28. if(y(position-b)=='+')
  29. coffecinet = coffecinet * -1 ;
  30. end
  31. end
  32. if(y(position - 1) ~= '*')
  33. coffecinet = 1;
  34. if(y(position-1)=='+')
  35. coffecinet = coffecinet * -1 ;
  36. end
  37. end
  38. end
  39. n=n+1;
  40. end
  41. z = sprintf('%s%s','@(x) ',y);
  42. func = str2func(z);
  43. cof = num2str(coffecinet);
  44. fun = strcat(cof,'*x');
  45. h = sprintf('%s%s','@(x) ',fun);
  46. func2 = str2func(h);
  47. g1=sym(func);
  48. g2=sym(func2);
  49. g3 = (g1 + g2)/coffecinet;
  50. disp(g3);
  51. gh = char(g3);
  52. cat = strcat('@(x) ',gh);
  53. func=str2func(cat);
  54. disp(func);
  55. disp(coffecinet);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement