Why can't I put two equations in one function file?

function a,b=myfunction(x)
a= @(x) 5-5*exp((1/3)*x) + (16- x^2)^(1/2)
b= @(x) (-5/3)*exp((1/3)*x) - (16- x^2)^(-1/2)
I basically want this function to give me f(x) value (equation listed next to a), and I want it to give me the f'(x) value (equation listed next to b).
Why is it that I can't have my input value go into two separate equations and come out as two outputs?
----
I know that I can create a function file f(x) with equation '5x^2 + 10' and then create its derivative function file:
function result= fd(x)
f(x)
result=10x;
and it will print out both values that I want (f(x) and f'(x)). But, do I really have to make two files for these two equations instead of just grouping them in one file?

回答 (1 件)

the cyclist
the cyclist 2018 年 2 月 28 日
編集済み: the cyclist 2018 年 2 月 28 日

2 投票

It's just a simple syntax error. Try
function [a,b]=myfunction(x)
Note the square brackets around the outputs. You will get two outputs from this function.

4 件のコメント

Rachel Dawn
Rachel Dawn 2018 年 2 月 28 日
I did that and took off the "@(x)" and it finally worked. Thank you!!
the cyclist
the cyclist 2018 年 2 月 28 日
Happy to help. The best form of thanks is to upvote and/or accept an answer, which rewards the contributor, and can guide future users to helpful responses.
PRED LIU
PRED LIU 2020 年 5 月 1 日
If a,b are matrix or ,how to do ??
IF a is matrix b is var ,how to do??
the cyclist
the cyclist 2020 年 5 月 1 日
It's still the same syntax. You will get outputs that are scalars or matrices.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeFunctions についてさらに検索

質問済み:

2018 年 2 月 28 日

コメント済み:

2020 年 5 月 1 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by